diff options
author | Artur Neumann <info@individual-it.net> | 2017-02-27 12:34:15 +0545 |
---|---|---|
committer | Artur Neumann <info@individual-it.net> | 2017-02-28 07:38:11 +0545 |
commit | f1fccaca0605a5d183f78b2c39d2e09a54753787 (patch) | |
tree | b63d877889120d12bc59e2103ad64c1568e8186b /core/js/js.js | |
parent | d0c6179ec18d1e2c3ce86bdf03f36aaa1501c6e7 (diff) | |
download | nextcloud-server-f1fccaca0605a5d183f78b2c39d2e09a54753787.tar.gz nextcloud-server-f1fccaca0605a5d183f78b2c39d2e09a54753787.zip |
better quota validation
this fixes #3634
1. fixed computerFileSize to be more picky about incorrect values
2. more tests for computerFileSize
3. use computerFileSize to validate user quota
Signed-off-by: Artur Neumann <info@individual-it.net>
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/core/js/js.js b/core/js/js.js index 3651635541a..ba831e4251d 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1678,16 +1678,12 @@ OC.Util = { * */ computerFileSize: function (string) { - if (typeof string != 'string') { + if (typeof string !== 'string') { return null; } var s = string.toLowerCase(); - var bytes = parseFloat(s) - - if (!isNaN(bytes) && isFinite(s)) { - return bytes; - } + var bytes = null; var bytesArray = { 'b' : 1, @@ -1703,12 +1699,18 @@ OC.Util = { 'p' : 1024 * 1024 * 1024 * 1024 * 1024 }; - var matches = s.match(/([kmgtp]?b?)$/i); - if (matches[1]) { - bytes = bytes * bytesArray[matches[1]]; + var matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i); + if (matches !== null) { + bytes = parseFloat(s); + if (!isFinite(bytes)) { + return null; + } } else { return null; } + if (matches[5]) { + bytes = bytes * bytesArray[matches[5]]; + } bytes = Math.round(bytes); return bytes; |