aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
authorPatrick Paysant <patrick.paysant@linagora.com>2016-12-07 11:43:44 +0100
committerLukas Reschke <lukas@statuscode.ch>2016-12-19 17:29:20 +0100
commitd4c088cb796f22545f79379c27145ef6285d2d5e (patch)
tree18342dca9cd85cc1da274043b3db1df46c625e29 /core/js/js.js
parentec4bca619d7cd57271262928b1fe06d5f8dc3211 (diff)
downloadnextcloud-server-d4c088cb796f22545f79379c27145ef6285d2d5e.tar.gz
nextcloud-server-d4c088cb796f22545f79379c27145ef6285d2d5e.zip
Verify input, add more unit tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'core/js/js.js')
-rw-r--r--core/js/js.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/core/js/js.js b/core/js/js.js
index f2cdf7c93ef..3651635541a 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1670,21 +1670,26 @@ OC.Util = {
/**
* Returns a file size in bytes from a humanly readable string
+ * Makes 2kB to 2048.
+ * Inspired by computerFileSize in helper.php
* @param {string} string file size in human readable format
* @return {number} or null if string could not be parsed
*
- * Makes 2kB to 2048.
*
- * Inspired by computerFileSize in helper.php
*/
computerFileSize: function (string) {
+ if (typeof string != 'string') {
+ return null;
+ }
+
var s = string.toLowerCase();
+ var bytes = parseFloat(s)
- if (!isNaN(parseFloat(s)) && isFinite(s)) {
- return parseFloat(s);
+ if (!isNaN(bytes) && isFinite(s)) {
+ return bytes;
}
- var bytes_array = {
+ var bytesArray = {
'b' : 1,
'k' : 1024,
'kb': 1024,
@@ -1698,13 +1703,10 @@ OC.Util = {
'p' : 1024 * 1024 * 1024 * 1024 * 1024
};
- var bytes = parseFloat(s);
-
var matches = s.match(/([kmgtp]?b?)$/i);
if (matches[1]) {
- bytes = bytes * bytes_array[matches[1]];
- }
- else {
+ bytes = bytes * bytesArray[matches[1]];
+ } else {
return null;
}