Skip to content

Improve toKilobytes to handle spaces and case-insensitive units #55019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025

Conversation

alikhosravidev
Copy link
Contributor

Changes:

  • Trimmed input (trim($size)) to remove extra spaces.
  • Converted input to lowercase (strtolower($size)) for case-insensitive unit matching.
  • Updated tests to cover inputs like "5MB", " 2gb ", and "1Tb".

🔹 Why?
Previously, toKilobytes only worked with strictly formatted units (1mb, 5gb, etc.). This update improves flexibility, ensuring better user experience and avoiding unnecessary validation failures.

🔹 Benefits:
✅ More flexible and user-friendly input handling.
✅ Fully backward-compatible with existing validation rules.
✅ Ensures size(), min(), max(), and between() work reliably with various input formats.

🚀 Ready for review & merge!

@taylorotwell taylorotwell merged commit c596d64 into laravel:12.x Mar 14, 2025
39 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