[13.x] Cast to string before preg_match in decimal, max_digits, and min_digits rules#59739
Merged
taylorotwell merged 2 commits intolaravel:13.xfrom Apr 17, 2026
Merged
Conversation
…x_digits, and min_digits rules Co-Authored-By: Sumaiya Zaman <saktar50.cse@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validateDecimal,validateMaxDigits, andvalidateMinDigitsnow explicitly cast the value tostringbefore passing it topreg_matchContext
decimalpreg_match('/^[+-]?\d*\.?(\d*)$/', $value, ...)preg_match('/^[+-]?\d*\.?(\d*)$/', (string) $value, ...)max_digitspreg_match('/[^0-9]/', $value)preg_match('/[^0-9]/', (string) $value)min_digitspreg_match('/[^0-9]/', $value)preg_match('/[^0-9]/', (string) $value)All three rules already check
is_string($value) || is_numeric($value)before thepreg_matchcall, so numeric types are valid inputs. Thestrlen()call in the same methods already casts with(string) $value— makingpreg_matchthe only place relying on PHP's implicit cast.This follows the same convention used in
validateAlphaDashandvalidateAlphaNum, and matches the fix applied tovalidateDigitsBetweenpreviously.Solution
Added an explicit
(string)cast to the$valueargument in eachpreg_matchcall.Example
Before:
After:
Why no breaking changes
The cast produces the same string that PHP would have generated implicitly. Existing behavior is preserved; only the expression is made explicit.
Changes
src/Illuminate/Validation/Concerns/ValidatesAttributes.php— three(string)casts addedtests/Validation/ValidationValidatorTest.php— added integer/float assertions to the three relevant test methodsTest Plan
php83 vendor/bin/phpunit tests/Validation/ValidationValidatorTest.php --filter "testValidateDecimal|testValidateMaxDigits|testValidateMinDigits"— all 3 tests, 65 assertions pass