summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-29 10:15:17 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-07-29 10:15:17 +0200
commit81d9066dc58811f88d144100cd792a19004e16f1 (patch)
tree03de4fc6eea46ea3f7b24dc12a7379930a2567d3 /core/js
parente77b2e53179d24deee1fe720f7a60b5db6f5c502 (diff)
parent5a0d41048868eddd709c6e9bb71a8c5243d239c0 (diff)
downloadnextcloud-server-81d9066dc58811f88d144100cd792a19004e16f1.tar.gz
nextcloud-server-81d9066dc58811f88d144100cd792a19004e16f1.zip
Merge pull request #17489 from owncloud/fix-share-time-as-string
Fix parsing of sharetime as string
Diffstat (limited to 'core/js')
-rw-r--r--core/js/share.js21
-rw-r--r--core/js/tests/specs/shareSpec.js16
2 files changed, 37 insertions, 0 deletions
diff --git a/core/js/share.js b/core/js/share.js
index d730d3bbf6e..99fd08c6411 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -820,6 +820,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
@@ -834,6 +853,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 4e12f3bb0cf..3dc25134f59 100644
--- a/core/js/tests/specs/shareSpec.js
+++ b/core/js/tests/specs/shareSpec.js
@@ -1316,5 +1316,21 @@ describe('OC.Share tests', function() {
});
});
});
+ 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]);
+ });
+
+ });
+ });
});