Skip to content

Fix grapheme searches with an offset inside a contraction - #26101

Closed
ChrisAbner wants to merge 1 commit into
php:PHP-8.4from
ChrisAbner:fix-grapheme-search-contraction
Closed

ChrisAbner wants to merge 1 commit into
php:PHP-8.4from
ChrisAbner:fix-grapheme-search-contraction

Conversation

@ChrisAbner

Copy link
Copy Markdown
Contributor

When the search position falls inside a contraction that spans graphemes, such as a Thai prevowel and its consonant, usearch_next() returns the match that starts at the contraction, before that position:

grapheme_strpos("และและ", "และ", 1);  // 0 instead of 3
grapheme_strrpos("เรา", "เรา", -1);  // never returns

The first one also makes the usual loop over all matches ($offset = $pos + 1) never end. The second one comes from the negative offset loop added in GH-24028, which sets the same position again forever. It is in 8.4.27 and later.

The search now starts again from the following grapheme boundaries, so a match that overlaps the skipped one is still found. This affects Thai, Lao and other scripts with prevowels. On 8.5, a $locale with such tailorings, like Danish "aa", reaches it too. Tests added.

When the search position falls inside a contraction that spans graphemes,
such as a Thai prevowel and its consonant, usearch_next() returns the
match that starts at the contraction. grapheme_strpos() then returned a
position before the offset, and the negative offset loop of
grapheme_strrpos() set the same position again forever.

The search now starts again from the following grapheme boundaries, so a
match that overlaps the skipped one is still found.
@devnexen devnexen closed this in 564e956 Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants