[wp-trac] [WordPress Trac] #61930: size_format(): Inconsistent behaviour when zero bytes are passed

WordPress Trac noreply at wordpress.org
Mon Aug 26 22:39:38 UTC 2024


#61930: size_format(): Inconsistent behaviour when zero bytes are passed
--------------------------+-----------------------------
 Reporter:  marian1       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.6.1
 Severity:  trivial       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The `size_format()` function returns `false` if zero is passed as a string
 and returns `'0 B'` if zero is passed as an integer.

 The root cause is a strict comparison when checking against zero (`if ( 0
 === $bytes ) {`). If the `$bytes` parameter is passed as a string (`'0'`),
 the condition fails.

 Proposed Fix: `if ( 0 === $bytes || '0' === $bytes ) {`

 This behaviour was introduced in WP 4.6.0. Before v4.6.0, both `0` and
 `'0'` resulted in `size_format()` returning `false`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61930>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list