Skip to content

[12.x] Fix Number::fileSize() handling of negative byte values#60147

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
Amirhf1:fix/number-filesize-negative
May 17, 2026
Merged

[12.x] Fix Number::fileSize() handling of negative byte values#60147
taylorotwell merged 1 commit into
laravel:12.xfrom
Amirhf1:fix/number-filesize-negative

Conversation

@Amirhf1
Copy link
Copy Markdown
Contributor

@Amirhf1 Amirhf1 commented May 16, 2026

Number::fileSize() does not scale negative byte values to the
appropriate unit, while Number::forHumans() in the same class does.

The loop condition uses ($bytes / 1024) > 0.9, which is never true
for a negative number, so the loop never runs and the value is always
returned in bytes:

Number::fileSize(-2048);    // "-2,048 B"  expected "-2 KB"
Number::fileSize(-1536000); // "-1,536,000 B"  expected "-1 MB"

@Amirhf1 Amirhf1 changed the base branch from 13.x to 12.x May 16, 2026 23:16
@taylorotwell taylorotwell merged commit 7c08356 into laravel:12.x May 17, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants