]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix parsing of sharetime as string
authorMorris Jobke <hey@morrisjobke.de>
Wed, 8 Jul 2015 13:23:01 +0000 (15:23 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Wed, 29 Jul 2015 12:58:54 +0000 (14:58 +0200)
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
core/js/tests/specs/shareSpec.js

index d8930727cfd968c45de130d12bcee382857e2e85..94833a8d915921bd57c8dd23f547dd2b79363d84 100644 (file)
@@ -764,6 +764,21 @@ OC.Share={
        dirname:function(path) {
                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
         *
@@ -779,6 +794,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);
                }
index ffde885d2b6676c4cde7fb944b5980f9e527ba7d..22632a2bd2e5321a14ef622dfbd6b5d9a2572255 100644 (file)
@@ -836,5 +836,19 @@ 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],
+                       ], function(value) {
+                               expect(OC.Share._parseTime(value[0])).toEqual(value[1]);
+                       });
+
+               });
+       });
 });