From e6a74136f9287f551d97fa0277f654ea09f3f69c Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 5 Jan 2015 13:13:23 +0000 Subject: [PATCH] `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. Built from https://develop.svn.wordpress.org/trunk@31052 git-svn-id: http://core.svn.wordpress.org/trunk@31033 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 11 +++++++---- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 00480d6848..3b69570bf3 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -182,7 +182,7 @@ function number_format_i18n( $number, $decimals = 0 ) { /** * Convert number of bytes largest unit bytes will fit into. * - * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts + * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts * number of bytes to human readable number by taking the number of that unit * that the bytes will go into it. Supports TB value. * @@ -206,11 +206,14 @@ function size_format( $bytes, $decimals = 0 ) { 'GB' => 1073741824, // pow( 1024, 3) 'MB' => 1048576, // pow( 1024, 2) 'kB' => 1024, // pow( 1024, 1) - 'B ' => 1, // pow( 1024, 0) + 'B' => 1, // pow( 1024, 0) ); - foreach ( $quant as $unit => $mag ) - if ( doubleval($bytes) >= $mag ) + + foreach ( $quant as $unit => $mag ) { + if ( doubleval( $bytes ) >= $mag ) { return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; + } + } return false; } diff --git a/wp-includes/version.php b/wp-includes/version.php index a5e84f668d..95ed650598 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31051'; +$wp_version = '4.2-alpha-31052'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.