WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#37037 closed defect (bug) (fixed)

size_format() incorrectly displays `kB` with small `k`

Reported by: dashaluna Owned by: Presskopp
Milestone: 4.6 Priority: normal
Severity: normal Version: 2.3
Component: General Keywords: good-first-bug has-patch
Focuses: Cc:

Description

The size_format() incorrectly displays kB unit. It should be KB.

Attachments (4)

37037.diff (658 bytes) - added by lukecavanagh 4 years ago.
Patch for deprecated.php
37037.patch (3.5 KB) - added by Presskopp 4 years ago.
kb => KB, that's all
37037.1.diff (3.5 KB) - added by Presskopp 4 years ago.
there was a typo, missing '
37037.2.diff (1.2 KB) - added by Presskopp 4 years ago.
let the externals alone

Download all attachments as: .zip

Change History (17)

#1 @swissspidy
4 years ago

  • Keywords needs-patch good-first-bug added

… because 1 kB means 1000 bytes, whereas 1 KB = 1 KiB = 1024 bytes.

size_format() assumes that 1024 bytes = 1 kB, so yeah, that sounds wrong.

#2 @pento
4 years ago

Related: #31350.

I don't mind this change - traditionally, kB has been the most common usage, but it seems to have changed to KB over the years, shifting from the SI standard, where kB = 1000 bytes, to the JEDEC standard, where KB = 1024 bytes.

Switching to the IEC standard (KiB, etc) is a much bigger discussion, particularly because those units have never really seen significant uptake. (Because they look weird, and all of the units are really awkward to say.)

#3 @dashaluna
4 years ago

I feel that whatever the decision will be, it should be consistent. As we're displaying file sizes in a table with all measurements being in capitals and kB looks like an oversight.

You get something looking:

GB
MB
kB
B

Sorry for being pedantic :)

#4 @Presskopp
4 years ago

IMHO we could just keep kB, even it maybe painful for your eyes, @dashaluna :)
See Table here: https://en.wikipedia.org/wiki/Kilobyte

Just for the record, we see it used here:

\wp-includes\ID3\module.audio.mp3.php, L.1375

round($sync_seek_buffer_size / 1024).'kB';

and as a comment here:

\wp-includes\ID3\module.audio-video.riff.php, L.1695

		} elseif ($chunksize < 2048) {
			// only read data in if smaller than 2kB

#5 @DrewAPicture
4 years ago

@Presskopp Care to add a patch?

#6 follow-up: @Presskopp
4 years ago

@DrewAPicture Why not, so you say it should be patched to KB?

If so, we also have it in

wp-includes/deprecated.php, L 3238

	$units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );

As it's deprecated, would this also be needed to get patched?

And what if @dashaluna wants to create a patch herself?

#7 in reply to: ↑ 6 @DrewAPicture
4 years ago

Replying to Presskopp:

@DrewAPicture Why not, so you say it should be patched to KB?

If so, we also have it in

wp-includes/deprecated.php, L 3238

	$units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );

As it's deprecated, would this also be needed to get patched?

And what if @dashaluna wants to create a patch herself?

Yes, let's standardize on uppercase. If either you or @dashaluna would like to generate a patch, that would be fine :-)

@lukecavanagh
4 years ago

Patch for deprecated.php

@Presskopp
4 years ago

kb => KB, that's all

@Presskopp
4 years ago

there was a typo, missing '

#8 @Presskopp
4 years ago

  • Keywords has-patch added; needs-patch removed

#9 @DrewAPicture
4 years ago

  • Owner set to Presskopp
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

#10 @ocean90
4 years ago

  • Version changed from trunk to 2.3

Introduced in [5801].

@Presskopp External libraries like ID3 shouldn't be changed.

@Presskopp
4 years ago

let the externals alone

#11 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 4.6

#12 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 37702:

In size_format() and wp_convert_bytes_to_hr(), replace kB with KB for consistency with other units.

Props Presskopp, dashaluna.
Fixes #37037.

#13 @SergeyBiryukov
4 years ago

In 37705:

After [37702], correct the expected result in test_size_format().

See #37037.

Note: See TracTickets for help on using tickets.