Repository navigation
Fix mbregex retry-limit failures in Multibyte::trim - #39
Merged
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.
Closes #27.
Long internal whitespace runs cause the trailing
\s*$alternative inMultibyte::trim()to backtrack and retry from successive positions. This can exhaust mbregex's retry limit, emit a warning, and returnfalseinstead of the original text.Use absolute string anchors, possessive whitespace quantifiers, and a negative whitespace lookbehind for the trailing alternative. Each whitespace run is consumed without backtracking and cannot be retried from inside the run. This retains mbregex's encoding and Unicode whitespace support without increasing retry limits or suppressing errors.
Regression coverage includes the reporter's exact 801/1348-space input, the same input with surrounding whitespace, a 20,000-space internal run, empty and whitespace-only strings, CR/LF/tab boundaries, internal newlines, non-breaking spaces, ideographic spaces, and multibyte text. Tests explicitly set and restore UTF-8 for the fixtures and lower
mbstring.regex_retry_limitto 1000 when available; PHPUnit restores the limit afterward. Older PHP versions still run the same input cases.Validation:
retry-limit-in-match overerrors with the limit set to 1000, including the reported input. Current local runtimes did not fail on that input at their default limit.composer test, PHP 8.2.10 / PHPUnit 9.6.37: 47 tests, 133 assertions passed.composer validate --strictandgit diff --checkpassed.phpunit.xmllegacy<filter>configuration warning, also present before this change.