diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-08-19 14:24:27 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-08-19 14:24:27 +0200 |
commit | 77b5ba92133f666516209fda296b6a7cf7717a89 (patch) | |
tree | 127ef418b54db65bc3f610fd4848418948de0492 | |
parent | 10a5b1b19d2b08c5fc02f58d0f2337e1cc9cc25f (diff) | |
parent | fc3ce8441e3a33b312fca3ea352ce1297a51a37d (diff) | |
download | nextcloud-server-77b5ba92133f666516209fda296b6a7cf7717a89.tar.gz nextcloud-server-77b5ba92133f666516209fda296b6a7cf7717a89.zip |
Merge pull request #17958 from owncloud/stable8-backport-17489
[stable8] Fix parsing of sharetime as string
-rw-r--r-- | core/js/share.js | 21 | ||||
-rw-r--r-- | core/js/tests/specs/shareSpec.js | 16 |
2 files changed, 37 insertions, 0 deletions
diff --git a/core/js/share.js b/core/js/share.js index d8930727cfd..2f126eca32c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -765,6 +765,25 @@ OC.Share={ return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); }, /** + * Parses a string to an valid integer (unix timestamp) + * @param time + * @returns {*} + * @internal Only used to work around a bug in the backend + */ + _parseTime: function(time) { + if (_.isString(time)) { + // skip empty strings and hex values + if (time === '' || (time.length > 1 && time[0] === '0' && time[1] === 'x')) { + return null; + } + time = parseInt(time, 10); + if(isNaN(time)) { + time = null; + } + } + return time; + }, + /** * Displays the expiration date field * * @param {Date} date current expiration date @@ -779,6 +798,8 @@ OC.Share={ minDate: minDate, maxDate: null }; + // TODO: hack: backend returns string instead of integer + shareTime = OC.Share._parseTime(shareTime); if (_.isNumber(shareTime)) { shareTime = new Date(shareTime * 1000); } diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index ffde885d2b6..eaeba79797c 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -836,5 +836,21 @@ describe('OC.Share tests', function() { }); // TODO: add unit tests for share recipients }); + describe('OC.Share utils', function() { + it('parseTime should properly parse strings', function() { + + _.each([ + [ '123456', 123456], + [ 123456 , 123456], + ['0123456', 123456], + ['abcdefg', null], + ['0x12345', null], + [ '', null], + ], function(value) { + expect(OC.Share._parseTime(value[0])).toEqual(value[1]); + }); + + }); + }); }); |