Merge pull request #13771 from owncloud/fix-humanfileSize
generate valid human readable text for 0
This commit is contained in:
commit
dfcd4acd5a
|
@ -1213,7 +1213,7 @@ $.fn.filterAttr = function(attr_name, attr_value) {
|
||||||
function humanFileSize(size, skipSmallSizes) {
|
function humanFileSize(size, skipSmallSizes) {
|
||||||
var humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
|
var humanList = ['B', 'kB', 'MB', 'GB', 'TB'];
|
||||||
// Calculate Log with base 1024: size = 1024 ** order
|
// Calculate Log with base 1024: size = 1024 ** order
|
||||||
var order = size?Math.floor(Math.log(size) / Math.log(1024)):0;
|
var order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0;
|
||||||
// Stay in range of the byte sizes that are defined
|
// Stay in range of the byte sizes that are defined
|
||||||
order = Math.min(humanList.length - 1, order);
|
order = Math.min(humanList.length - 1, order);
|
||||||
var readableFormat = humanList[order];
|
var readableFormat = humanList[order];
|
||||||
|
|
|
@ -465,6 +465,8 @@ describe('Core base tests', function() {
|
||||||
it('renders file sizes with the correct unit', function() {
|
it('renders file sizes with the correct unit', function() {
|
||||||
var data = [
|
var data = [
|
||||||
[0, '0 B'],
|
[0, '0 B'],
|
||||||
|
["0", '0 B'],
|
||||||
|
["A", 'NaN B'],
|
||||||
[125, '125 B'],
|
[125, '125 B'],
|
||||||
[128000, '125 kB'],
|
[128000, '125 kB'],
|
||||||
[128000000, '122.1 MB'],
|
[128000000, '122.1 MB'],
|
||||||
|
|
Loading…
Reference in New Issue