Skip to content

Respect the encoding in Str::mask() when building the end of the string#60646

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
iammcoding:fix-str-mask-encoding
Jul 2, 2026
Merged

Respect the encoding in Str::mask() when building the end of the string#60646
taylorotwell merged 1 commit into
laravel:13.xfrom
iammcoding:fix-str-mask-encoding

Conversation

@iammcoding

Copy link
Copy Markdown
Contributor

Str::mask() accepts an $encoding argument and passes it to every mb_ call except the one that builds the portion of the string after the masked segment. That last mb_substr() used mb_substr()'s default encoding, so when a non UTF-8 encoding was passed the tail was sliced at the wrong character offsets and any multibyte characters after the mask got corrupted.

For example, masking an ISO-8859-1 string turned "García" into "Garc?a". Passing $encoding to that mb_substr() call fixes it. Added assertions that mask an ISO-8859-1 string using both a positive and a negative index.

Str::mask() accepts an $encoding argument and passes it to every mb_
call except the one that builds the portion of the string after the
masked segment. That last mb_substr() used mb_substr()'s default
encoding, so when a non UTF-8 encoding was passed the tail was sliced at
the wrong character offsets and any multibyte characters after the mask
got corrupted.

For example, masking an ISO-8859-1 string turned "García" into "Garc?a".
Passing $encoding to that mb_substr() call fixes it. Added assertions
that mask an ISO-8859-1 string using both a positive and a negative
index.
@taylorotwell taylorotwell merged commit 8ce2bbe into laravel:13.x Jul 2, 2026
1 check 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