[intl] Fix empty-needle grapheme_strpos offsets - #23519
Open
iliaal wants to merge 1 commit into
Open
Conversation
NickSdot
reviewed
Aug 31, 2026
devnexen
approved these changes
Aug 31, 2026
grapheme_strpos_utf16() returned raw UTF-16 code-unit positions for an empty needle instead of grapheme counts, so multi-code-unit graphemes made strpos() and strrpos() over-report the offset. Convert the boundary position like the non-empty search path; the ASCII fast paths coincide and grapheme_strstr() consumes the separate raw UTF-16 out-parameter, which stays correct.
iliaal
force-pushed
the
fix/grapheme-empty-offset-84
branch
from
August 31, 2026 17:43
8db9a85 to
922baf6
Compare
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.
grapheme_strpos() and grapheme_strrpos() with an empty needle return the raw UTF-16 code-unit position instead of a grapheme index, so on a haystack containing a non-BMP or combining grapheme the reported offset is too large: grapheme_strpos("😀x", "", 1) gives 3 where 1 is correct. The empty-needle early return in grapheme_strpos_utf16() skips the grapheme_count_graphemes() conversion that the non-empty search already does. grapheme_strstr() is unaffected: it consumes the separate raw UTF-16 out-parameter, not the return value.