[13.x] Fix TypeError in digits_between validation rule on non-string values#59717
Merged
taylorotwell merged 2 commits intolaravel:13.xfrom Apr 16, 2026
Merged
Conversation
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
This PR fixes a
TypeErrorthrown by thedigits_betweenvalidation rule when a non-string, non-numeric value (such as an array) is passed. The rule callspreg_match()directly on the value without first checking its type, causing PHP 8 to throw aTypeErrorinstead of returning a clean validation failure.Context
Several validation rules have already received this same fix:
starts_withStr::startsWith()type-hintends_withStr::endsWith()type-hintdoesnt_start_withStr::startsWith()type-hintdoesnt_end_withStr::endsWith()type-hintlowercaseStr::lower()type-hintuppercaseStr::upper()type-hintasciiStr::isAscii()hex_colorpreg_match()on arraymax_digitspreg_match()on arraymin_digitspreg_match()on arraydigitspreg_match()on arraydigits_betweenpreg_match()on arraydigits_betweenis the only remaining rule in this family without a type guard. Its siblingdigitsis protected by an inline check —digits_betweenwas simply missed.Solution
Added the same
is_string/is_numericguard used inmax_digitsandmin_digits:Example
Why This Doesn't Break Existing Features
digits_between— now they fail cleanly instead of throwingmax_digits,min_digits, and implicitly indigitsChanges
src/Illuminate/Validation/Concerns/ValidatesAttributes.php— Added type guard tovalidateDigitsBetween()tests/Validation/ValidationValidatorTest.php— Added array assertion totestValidateDigits()and a dedicatedtestValidateDigitsBetweenDoesNotThrowOnNonStringValue()testTest Plan
testValidateDigitsBetweenDoesNotThrowOnNonStringValue— Verifies array input returnsfalseinstead of throwingTypeErrortestValidateDigits— Existing test updated with array case fordigits_between