Skip to content

Commit cf05370

Browse files
v1.0.420
[Bot] push changes from Files.com
1 parent e60e2fe commit cf05370

8 files changed

+56
-14
lines changed

_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.419
1+
1.0.420

lib/Files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var endpointPrefix = '/api/rest/v1';
1111
var apiKey;
1212
var baseUrl = 'https://app.files.com';
1313
var sessionId = null;
14-
var version = "1.0.419";
14+
var version = "1.0.420";
1515
var userAgent = "Files.com JavaScript SDK v".concat(version);
1616
var logLevel = _Logger.LogLevel.INFO;
1717
var debugRequest = false;

lib/utils/pathNormalizer.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var transliterate = function transliterate(str) {
198198
// converting the path to UTF-8 is not necessary in JS as it's the default
199199
var normalize = function normalize(path) {
200200
// Remove any characters with byte value of 0
201-
var cleaned = (path || '').replace(/\0/g, '');
201+
var cleaned = (typeof path === 'string' ? path : '').replace(/\0/g, '');
202202

203203
// Convert any backslash (\) characters to a forward slash (/)
204204
cleaned = cleaned.replace(/\\/g, '/');
@@ -239,20 +239,21 @@ var normalizeForComparison = function normalizeForComparison(path) {
239239
return normalized;
240240
};
241241
var same = function same(path1, path2) {
242-
return normalizeForComparison(path1) === normalizeForComparison(path2);
242+
return typeof path1 === 'string' && typeof path2 === 'string' && normalizeForComparison(path1) === normalizeForComparison(path2);
243243
};
244244
var startsWith = function startsWith(path1, path2) {
245-
return normalizeForComparison(path1).startsWith(normalizeForComparison(path2));
245+
return typeof path1 === 'string' && typeof path2 === 'string' && normalizeForComparison(path1).startsWith(normalizeForComparison(path2));
246246
};
247247
var keyLookup = function keyLookup(object, path) {
248-
var key = Object.keys(object).find(function (key) {
248+
var key = Object.keys(object || {}).find(function (key) {
249249
return same(key, path);
250250
});
251251
return typeof key === 'string' ? object[key] : undefined;
252252
};
253253
var pathNormalizer = {
254254
keyLookup: keyLookup,
255255
normalize: normalize,
256+
normalizeForComparison: normalizeForComparison,
256257
same: same,
257258
startsWith: startsWith
258259
};

lib/utils/pathNormalizer.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ describe('pathNormalizer', function () {
1515
expect(_pathNormalizer.default.startsWith(input, startOfExpected)).toBe(true);
1616
});
1717
});
18+
it('handles non-string params', function () {
19+
expect(_pathNormalizer.default.normalize([])).toBe('');
20+
expect(_pathNormalizer.default.normalize({})).toBe('');
21+
expect(_pathNormalizer.default.normalize(null)).toBe('');
22+
expect(_pathNormalizer.default.normalize(undefined)).toBe('');
23+
expect(_pathNormalizer.default.same([], '')).toBe(false);
24+
expect(_pathNormalizer.default.same(null, '')).toBe(false);
25+
expect(_pathNormalizer.default.same([], null)).toBe(false);
26+
expect(_pathNormalizer.default.same(undefined, undefined)).toBe(false);
27+
expect(_pathNormalizer.default.startsWith(null, '')).toBe(false);
28+
expect(_pathNormalizer.default.startsWith(null, [])).toBe(false);
29+
expect(_pathNormalizer.default.startsWith([], null)).toBe(false);
30+
expect(_pathNormalizer.default.startsWith(undefined, undefined)).toBe(false);
31+
expect(_pathNormalizer.default.keyLookup(null, '')).toBe(undefined);
32+
expect(_pathNormalizer.default.keyLookup(null, [])).toBe(undefined);
33+
expect(_pathNormalizer.default.keyLookup([], null)).toBe(undefined);
34+
expect(_pathNormalizer.default.keyLookup(undefined, undefined)).toBe(undefined);
35+
});
1836
it('looks up keys in a map', function () {
1937
var map = {
2038
'': {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "files.com",
3-
"version": "1.0.419",
3+
"version": "1.0.420",
44
"description": "Files.com SDK for JavaScript",
55
"keywords": [
66
"files.com",

src/Files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const endpointPrefix = '/api/rest/v1'
55
let apiKey
66
let baseUrl = 'https://app.files.com'
77
let sessionId = null
8-
let version = "1.0.419"
8+
let version = "1.0.420"
99
let userAgent = `Files.com JavaScript SDK v${version}`
1010

1111
let logLevel = LogLevel.INFO

src/utils/pathNormalizer.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const transliterate = str =>
193193
// converting the path to UTF-8 is not necessary in JS as it's the default
194194
const normalize = path => {
195195
// Remove any characters with byte value of 0
196-
let cleaned = (path || '').replace(/\0/g, '')
196+
let cleaned = (typeof path === 'string' ? path : '').replace(/\0/g, '')
197197

198198
// Convert any backslash (\) characters to a forward slash (/)
199199
cleaned = cleaned.replace(/\\/g, '/')
@@ -237,20 +237,21 @@ const normalizeForComparison = path => {
237237
return normalized
238238
}
239239

240-
const same = (path1, path2) =>
241-
normalizeForComparison(path1) === normalizeForComparison(path2)
240+
const same = (path1, path2) => typeof path1 === 'string' && typeof path2 === 'string'
241+
&& normalizeForComparison(path1) === normalizeForComparison(path2)
242242

243-
const startsWith = (path1, path2) =>
244-
normalizeForComparison(path1).startsWith(normalizeForComparison(path2))
243+
const startsWith = (path1, path2) => typeof path1 === 'string' && typeof path2 === 'string'
244+
&& normalizeForComparison(path1).startsWith(normalizeForComparison(path2))
245245

246246
const keyLookup = (object, path) => {
247-
const key = Object.keys(object).find(key => same(key, path))
247+
const key = Object.keys(object || {}).find(key => same(key, path))
248248
return typeof key === 'string' ? object[key] : undefined
249249
}
250250

251251
const pathNormalizer = {
252252
keyLookup,
253253
normalize,
254+
normalizeForComparison,
254255
same,
255256
startsWith,
256257
}

src/utils/pathNormalizer.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ describe('pathNormalizer', () => {
1212
})
1313
})
1414

15+
it('handles non-string params', () => {
16+
expect(pathNormalizer.normalize([])).toBe('')
17+
expect(pathNormalizer.normalize({})).toBe('')
18+
expect(pathNormalizer.normalize(null)).toBe('')
19+
expect(pathNormalizer.normalize(undefined)).toBe('')
20+
21+
expect(pathNormalizer.same([], '')).toBe(false)
22+
expect(pathNormalizer.same(null, '')).toBe(false)
23+
expect(pathNormalizer.same([], null)).toBe(false)
24+
expect(pathNormalizer.same(undefined, undefined)).toBe(false)
25+
26+
expect(pathNormalizer.startsWith(null, '')).toBe(false)
27+
expect(pathNormalizer.startsWith(null, [])).toBe(false)
28+
expect(pathNormalizer.startsWith([], null)).toBe(false)
29+
expect(pathNormalizer.startsWith(undefined, undefined)).toBe(false)
30+
31+
expect(pathNormalizer.keyLookup(null, '')).toBe(undefined)
32+
expect(pathNormalizer.keyLookup(null, [])).toBe(undefined)
33+
expect(pathNormalizer.keyLookup([], null)).toBe(undefined)
34+
expect(pathNormalizer.keyLookup(undefined, undefined)).toBe(undefined)
35+
})
36+
1537
it('looks up keys in a map', () => {
1638
const map = {
1739
'': { list: true },

0 commit comments

Comments
 (0)