Make WordPress Core


Ignore:
Timestamp:
01/05/2015 01:12:06 PM (7 years ago)
Author:
pento
Message:

size_format() incorrectly included a trailing space for B values: less than 1024 bytes.

Also add a unit test to check for this, so we don't do it again.

Fixes #30908.

Props tillkruess.

File:
1 edited

Legend:

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

    r31044 r31052  
    183183 * Convert number of bytes largest unit bytes will fit into.
    184184 *
    185  * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts
     185 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts
    186186 * number of bytes to human readable number by taking the number of that unit
    187187 * that the bytes will go into it. Supports TB value.
     
    207207        'MB' => 1048576,        // pow( 1024, 2)
    208208        'kB' => 1024,           // pow( 1024, 1)
    209         'B ' => 1,              // pow( 1024, 0)
     209        'B' => 1,              // pow( 1024, 0)
    210210    );
    211     foreach ( $quant as $unit => $mag )
    212         if ( doubleval($bytes) >= $mag )
     211
     212    foreach ( $quant as $unit => $mag ) {
     213        if ( doubleval( $bytes ) >= $mag ) {
    213214            return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
     215        }
     216    }
    214217
    215218    return false;
Note: See TracChangeset for help on using the changeset viewer.