[Pkg-owncloud-commits] [owncloud] 04/79: Fix parsing of sharetime as string

David Prévot taffit at moszumanska.debian.org
Tue Sep 1 20:55:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 4d6dcec751ee4ade3d5fa1d8f76f4e02abb24235
Author: Morris Jobke <hey at morrisjobke.de>
Date:   Wed Jul 8 15:23:01 2015 +0200

    Fix parsing of sharetime as string
    
    In some cases the ajax/share.php will return the share time as string.
    If this is the case it would get parsed completely wrong and cause the
    share dropdown to not work anymore. This change will properly cast the
    string to an interger and also fallback if this is not possible.
---
 core/js/share.js                 | 17 +++++++++++++++++
 core/js/tests/specs/shareSpec.js | 14 ++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/core/js/share.js b/core/js/share.js
index d730d3b..f767da1 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -820,6 +820,21 @@ 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)) {
+			time = parseInt(time, 10);
+			if(isNaN(time)) {
+				time = null;
+			}
+		}
+		return time;
+	},
+	/**
 	 * Displays the expiration date field
 	 *
 	 * @param {Date} date current expiration date
@@ -834,6 +849,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 4e12f3b..a8beb80 100644
--- a/core/js/tests/specs/shareSpec.js
+++ b/core/js/tests/specs/shareSpec.js
@@ -1316,5 +1316,19 @@ 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],
+			], function(value) {
+				expect(OC.Share._parseTime(value[0])).toEqual(value[1]);
+			});
+
+		});
+	});
 });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list