WordPress.org

Make WordPress Core

Changeset 37962


Ignore:
Timestamp:
07/05/2016 10:35:24 AM (4 years ago)
Author:
ocean90
Message:

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

Props swissspidy.
Fixes #36635.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r37944 r37962  
    263263        'B'  => 1,
    264264    );
     265
     266    if ( 0 === $bytes ) {
     267        return number_format_i18n( 0, $decimals ) . ' B';
     268    }
    265269
    266270    foreach ( $quant as $unit => $mag ) {
  • trunk/tests/phpunit/tests/functions.php

    r37718 r37962  
    5050        $this->assertInternalType( 'string', $args['foo'] );
    5151        $this->assertInternalType( 'string', $args['bar'] );
    52     }
    53 
    54     function test_size_format() {
    55         $b  = 1;
    56         $kb = 1024;
    57         $mb = $kb*1024;
    58         $gb = $mb*1024;
    59         $tb = $gb*1024;
    60         // test if boundaries are correct
    61         $this->assertEquals('1 GB', size_format($gb, 0));
    62         $this->assertEquals('1 MB', size_format($mb, 0));
    63         $this->assertEquals('1 KB', size_format($kb, 0));
    64         $this->assertEquals('1 B',  size_format($b, 0));
    65         // now some values around
    66         // add some bytes to make sure the result isn't 1.4999999
    67         $this->assertEquals('1.5 TB', size_format($tb + $tb/2 + $mb, 1));
    68         $this->assertEquals('1,023.999 GB', size_format($tb-$mb-$kb, 3));
    69         // edge
    70         $this->assertFalse(size_format(-1));
    71         $this->assertFalse(size_format(0));
    72         $this->assertFalse(size_format('baba'));
    73         $this->assertFalse(size_format(array()));
    7452    }
    7553
Note: See TracChangeset for help on using the changeset viewer.