files.com 1.0.419 → 1.0.420

Sign up to get free protection for your applications and to get access to all the features.
package/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.419
1
+ 1.0.420
package/lib/Files.js CHANGED
@@ -11,7 +11,7 @@ var endpointPrefix = '/api/rest/v1';
11
11
  var apiKey;
12
12
  var baseUrl = 'https://app.files.com';
13
13
  var sessionId = null;
14
- var version = "1.0.419";
14
+ var version = "1.0.420";
15
15
  var userAgent = "Files.com JavaScript SDK v".concat(version);
16
16
  var logLevel = _Logger.LogLevel.INFO;
17
17
  var debugRequest = false;
@@ -198,7 +198,7 @@ var transliterate = function transliterate(str) {
198
198
  // converting the path to UTF-8 is not necessary in JS as it's the default
199
199
  var normalize = function normalize(path) {
200
200
  // 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, '');
202
202
 
203
203
  // Convert any backslash (\) characters to a forward slash (/)
204
204
  cleaned = cleaned.replace(/\\/g, '/');
@@ -239,13 +239,13 @@ var normalizeForComparison = function normalizeForComparison(path) {
239
239
  return normalized;
240
240
  };
241
241
  var same = function same(path1, path2) {
242
- return normalizeForComparison(path1) === normalizeForComparison(path2);
242
+ return typeof path1 === 'string' && typeof path2 === 'string' && normalizeForComparison(path1) === normalizeForComparison(path2);
243
243
  };
244
244
  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));
246
246
  };
247
247
  var keyLookup = function keyLookup(object, path) {
248
- var key = Object.keys(object).find(function (key) {
248
+ var key = Object.keys(object || {}).find(function (key) {
249
249
  return same(key, path);
250
250
  });
251
251
  return typeof key === 'string' ? object[key] : undefined;
@@ -253,6 +253,7 @@ var keyLookup = function keyLookup(object, path) {
253
253
  var pathNormalizer = {
254
254
  keyLookup: keyLookup,
255
255
  normalize: normalize,
256
+ normalizeForComparison: normalizeForComparison,
256
257
  same: same,
257
258
  startsWith: startsWith
258
259
  };
@@ -15,6 +15,24 @@ describe('pathNormalizer', function () {
15
15
  expect(_pathNormalizer.default.startsWith(input, startOfExpected)).toBe(true);
16
16
  });
17
17
  });
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
+ });
18
36
  it('looks up keys in a map', function () {
19
37
  var map = {
20
38
  '': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.0.419",
3
+ "version": "1.0.420",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
package/src/Files.js CHANGED
@@ -5,7 +5,7 @@ const endpointPrefix = '/api/rest/v1'
5
5
  let apiKey
6
6
  let baseUrl = 'https://app.files.com'
7
7
  let sessionId = null
8
- let version = "1.0.419"
8
+ let version = "1.0.420"
9
9
  let userAgent = `Files.com JavaScript SDK v${version}`
10
10
 
11
11
  let logLevel = LogLevel.INFO
@@ -193,7 +193,7 @@ const transliterate = str =>
193
193
  // converting the path to UTF-8 is not necessary in JS as it's the default
194
194
  const normalize = path => {
195
195
  // 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, '')
197
197
 
198
198
  // Convert any backslash (\) characters to a forward slash (/)
199
199
  cleaned = cleaned.replace(/\\/g, '/')
@@ -237,20 +237,21 @@ const normalizeForComparison = path => {
237
237
  return normalized
238
238
  }
239
239
 
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)
242
242
 
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))
245
245
 
246
246
  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))
248
248
  return typeof key === 'string' ? object[key] : undefined
249
249
  }
250
250
 
251
251
  const pathNormalizer = {
252
252
  keyLookup,
253
253
  normalize,
254
+ normalizeForComparison,
254
255
  same,
255
256
  startsWith,
256
257
  }
@@ -12,6 +12,28 @@ describe('pathNormalizer', () => {
12
12
  })
13
13
  })
14
14
 
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
+
15
37
  it('looks up keys in a map', () => {
16
38
  const map = {
17
39
  '': { list: true },