[13.x] Fix multibyte case-insensitive matching in Str::replace and Str::remove#60882
Open
marekmiklusek wants to merge 2 commits into
Open
[13.x] Fix multibyte case-insensitive matching in Str::replace and Str::remove#60882marekmiklusek wants to merge 2 commits into
marekmiklusek wants to merge 2 commits into
Conversation
shaedrich
reviewed
Jul 24, 2026
Comment on lines
+1295
to
+1302
| * @param string|iterable<string> $search | ||
| * @param string|iterable<string> $replace | ||
| * @param string|iterable<string> $subject | ||
| * @return string|string[] | ||
| */ | ||
| protected static function replaceIgnoreCase($search, $replace, $subject) | ||
| { | ||
| $searches = is_array($search) ? array_values($search) : [$search]; |
Contributor
There was a problem hiding this comment.
I'm not sure but this probably breaks on non-array iterables, right?
Contributor
Author
There was a problem hiding this comment.
Good catch on the docblock! The method itself can only receive normalized
input, both public entry points (replace() and remove()) convert
Traversable searches via iterator_to_array() before calling it, and the
existing collect() test in testReplace covers that path. But the
iterable<string> docblock on the helper was inaccurate for what it
actually accepts, updated it to array|string. Thanks Man!
shaedrich
reviewed
Jul 24, 2026
Comment on lines
+1295
to
+1297
| * @param array|string $search | ||
| * @param array|string $replace | ||
| * @param array|string $subject |
Contributor
There was a problem hiding this comment.
You could probably narrow this down to
Suggested change
| * @param array|string $search | |
| * @param array|string $replace | |
| * @param array|string $subject | |
| * @param string|string[] $search | |
| * @param string|string[] $replace | |
| * @param string|string[] $subject |
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.
Str::replace()andStr::remove()with$caseSensitive = falsedelegateto
str_ireplace(), which only case-folds ASCII characters. Multibytecharacters are never matched case-insensitively:
This is inconsistent within the class itself ->
Str::contains()considersthe same strings a case-insensitive match:
ASCII-only search terms keep using
str_ireplace()exactly as before.Multibyte terms are matched via
preg_quote+/iupatterns with a callbackreplacement, replicating
str_ireplace()array pairing and sequentialsemantics. Subjects that are not valid UTF-8 fall back to
str_ireplace(),preserving the previous behavior.