aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-02-28 00:27:51 -0600
committerGitHub <noreply@github.com>2017-02-28 00:27:51 -0600
commit413d671d9e9d8928c062dac4b993db12a618c590 (patch)
tree2d38120e7b40c630c2030a05c2d885c298de5d54 /core/js/js.js
parent7fc3129f0cb80358c5b8f5c2b93f0aa446d1c317 (diff)
parent9790fe7f5d349df4f56c427cf3559d004067eae5 (diff)
downloadnextcloud-server-413d671d9e9d8928c062dac4b993db12a618c590.tar.gz
nextcloud-server-413d671d9e9d8928c062dac4b993db12a618c590.zip
Merge pull request #3635 from individual-it/fix_quota_validation
better quota validation
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 5f5f540af63..6fd66c9c9bb 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1712,16 +1712,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 s = string.toLowerCase().trim();
+ var bytes = null;
var bytesArray = {
'b' : 1,
@@ -1737,12 +1733,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;