aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
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;
}