WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#36635 closed defect (bug) (fixed)

Issue with size_format function when value is 0

Reported by: bangelov Owned by: ocean90
Milestone: 4.6 Priority: normal
Severity: normal Version: 2.3
Component: General Keywords: has-patch has-unit-tests commit
Focuses: Cc:
PR Number:

Description (last modified by swissspidy)

When you invoke size_format(0) function with zero value it should return 0 B instead it returns false which is wrong. For example when you are looping files and some of them is zero byte file it will return false and will break the UI if function is directly used in the view (most cases).

Attachments (3)

36635.diff (2.1 KB) - added by swissspidy 4 years ago.
36635.2.diff (3.4 KB) - added by swissspidy 4 years ago.
36635.3.diff (3.4 KB) - added by swissspidy 4 years ago.

Download all attachments as: .zip

Change History (11)

#1 @swissspidy
4 years ago

  • Description modified (diff)

#2 @swissspidy
4 years ago

  • Keywords needs-patch needs-unit-tests added
  • Version changed from 4.5 to 2.3

Seems legit to me. Will whip up a patch shortly.

@swissspidy
4 years ago

#3 @swissspidy
4 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
  • Milestone changed from Awaiting Review to 4.6

#4 @SergeyBiryukov
4 years ago

There are some size_format() tests in tests/functions.php, might be worth combining them.

Also related: #23626.

@swissspidy
4 years ago

#5 @swissspidy
4 years ago

Thanks @SergeyBiryukov, totally missed those!

36635.2.diff combines the tests.

#6 @ocean90
4 years ago

  • Keywords needs-refresh added

@swissspidy
4 years ago

#7 @swissspidy
4 years ago

  • Keywords commit added; needs-refresh removed

#8 @ocean90
4 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 37962:

General: Return "O B" when passing 0 to size_format().

Props swissspidy.
Fixes #36635.

Note: See TracTickets for help on using tickets.