Merge pull request #3635 from individual-it/fix_quota_validation
better quota validation
This commit is contained in:
commit
413d671d9e
|
@ -1712,16 +1712,12 @@ OC.Util = {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
computerFileSize: function (string) {
|
computerFileSize: function (string) {
|
||||||
if (typeof string != 'string') {
|
if (typeof string !== 'string') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = string.toLowerCase();
|
var s = string.toLowerCase().trim();
|
||||||
var bytes = parseFloat(s)
|
var bytes = null;
|
||||||
|
|
||||||
if (!isNaN(bytes) && isFinite(s)) {
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytesArray = {
|
var bytesArray = {
|
||||||
'b' : 1,
|
'b' : 1,
|
||||||
|
@ -1737,12 +1733,18 @@ OC.Util = {
|
||||||
'p' : 1024 * 1024 * 1024 * 1024 * 1024
|
'p' : 1024 * 1024 * 1024 * 1024 * 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
var matches = s.match(/([kmgtp]?b?)$/i);
|
var matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i);
|
||||||
if (matches[1]) {
|
if (matches !== null) {
|
||||||
bytes = bytes * bytesArray[matches[1]];
|
bytes = parseFloat(s);
|
||||||
|
if (!isFinite(bytes)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (matches[5]) {
|
||||||
|
bytes = bytes * bytesArray[matches[5]];
|
||||||
|
}
|
||||||
|
|
||||||
bytes = Math.round(bytes);
|
bytes = Math.round(bytes);
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
|
@ -594,8 +594,14 @@ describe('Core base tests', function() {
|
||||||
it('correctly parses file sizes from a human readable formated string', function() {
|
it('correctly parses file sizes from a human readable formated string', function() {
|
||||||
var data = [
|
var data = [
|
||||||
['125', 125],
|
['125', 125],
|
||||||
['125.25', 125.25],
|
['125.25', 125],
|
||||||
|
['125.25B', 125],
|
||||||
|
['125.25 B', 125],
|
||||||
['0 B', 0],
|
['0 B', 0],
|
||||||
|
['99999999999999999999999999999999999999999999 B', 99999999999999999999999999999999999999999999],
|
||||||
|
['0 MB', 0],
|
||||||
|
['0 kB', 0],
|
||||||
|
['0kB', 0],
|
||||||
['125 B', 125],
|
['125 B', 125],
|
||||||
['125b', 125],
|
['125b', 125],
|
||||||
['125 KB', 128000],
|
['125 KB', 128000],
|
||||||
|
@ -605,7 +611,21 @@ describe('Core base tests', function() {
|
||||||
['119.2 GB', 127990025421],
|
['119.2 GB', 127990025421],
|
||||||
['119.2gb', 127990025421],
|
['119.2gb', 127990025421],
|
||||||
['116.4 TB', 127983153473126],
|
['116.4 TB', 127983153473126],
|
||||||
['116.4tb', 127983153473126]
|
['116.4tb', 127983153473126],
|
||||||
|
['8776656778888777655.4tb', 9.650036181387265e+30],
|
||||||
|
[1234, null],
|
||||||
|
[-1234, null],
|
||||||
|
['-1234 B', null],
|
||||||
|
['B', null],
|
||||||
|
['40/0', null],
|
||||||
|
['40,30 kb', null],
|
||||||
|
[' 122.1 MB ', 128031130],
|
||||||
|
['122.1 MB ', 128031130],
|
||||||
|
[' 122.1 MB ', 128031130],
|
||||||
|
[' 122.1 MB ', 128031130],
|
||||||
|
['122.1 MB ', 128031130],
|
||||||
|
[' 125', 125],
|
||||||
|
[' 125 ', 125],
|
||||||
];
|
];
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
expect(OC.Util.computerFileSize(data[i][0])).toEqual(data[i][1]);
|
expect(OC.Util.computerFileSize(data[i][0])).toEqual(data[i][1]);
|
||||||
|
|
|
@ -554,7 +554,7 @@ var UserList = {
|
||||||
if (quota === 'other') {
|
if (quota === 'other') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((quota !== 'default' && quota !=="none") && (isNaN(parseInt(quota, 10)) || parseInt(quota, 10) < 0)) {
|
if ((quota !== 'default' && quota !=="none") && (!OC.Util.computerFileSize(quota))) {
|
||||||
// the select component has added the bogus value, delete it again
|
// the select component has added the bogus value, delete it again
|
||||||
$select.find('option[selected]').remove();
|
$select.find('option[selected]').remove();
|
||||||
OC.Notification.showTemporary(t('core', 'Invalid quota value "{val}"', {val: quota}));
|
OC.Notification.showTemporary(t('core', 'Invalid quota value "{val}"', {val: quota}));
|
||||||
|
|
Loading…
Reference in New Issue