Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
dfcd4acd
Commit
dfcd4acd
authored
Feb 12, 2015
by
Lukas Reschke
Browse files
Merge pull request #13771 from owncloud/fix-humanfileSize
generate valid human readable text for 0
parents
bd5440a8
ccc1f096
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/js/js.js
View file @
dfcd4acd
...
...
@@ -1213,7 +1213,7 @@ $.fn.filterAttr = function(attr_name, attr_value) {
function
humanFileSize
(
size
,
skipSmallSizes
)
{
var
humanList
=
[
'
B
'
,
'
kB
'
,
'
MB
'
,
'
GB
'
,
'
TB
'
];
// 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
order
=
Math
.
min
(
humanList
.
length
-
1
,
order
);
var
readableFormat
=
humanList
[
order
];
...
...
core/js/tests/specs/coreSpec.js
View file @
dfcd4acd
...
...
@@ -465,6 +465,8 @@ describe('Core base tests', function() {
it
(
'
renders file sizes with the correct unit
'
,
function
()
{
var
data
=
[
[
0
,
'
0 B
'
],
[
"
0
"
,
'
0 B
'
],
[
"
A
"
,
'
NaN B
'
],
[
125
,
'
125 B
'
],
[
128000
,
'
125 kB
'
],
[
128000000
,
'
122.1 MB
'
],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment