diff --git a/NEWS b/NEWS index 99df5910c8b5..fb0f05f502b5 100644 --- a/NEWS +++ b/NEWS @@ -74,6 +74,8 @@ PHP NEWS . Fixed grapheme_strstr() and grapheme_strpos() missing canonically equivalent matches, and grapheme searches reporting ICU errors for empty haystacks. (Weilin Du) + . Fixed grapheme_strrpos() and grapheme_strripos() skipping overlapping matches + when using a negative offset. (Weilin Du) - Lexbor: . Merge patches lexbor/lexbor@8a14bc0 and lexbor/lexbor@f67ce4b, fixing a diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c index dbe80d962765..cd337055d45d 100644 --- a/ext/intl/grapheme/grapheme_util.c +++ b/ext/intl/grapheme/grapheme_util.c @@ -184,6 +184,12 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, break; } prev_pos = char_pos; + int32_t next_pos = ubrk_following(bi, char_pos); + if (next_pos == UBRK_DONE) { + break; + } + usearch_setOffset(src, next_pos, &status); + STRPOS_CHECK_STATUS(status, "Invalid search offset"); } while(1); } } else { diff --git a/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt b/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt new file mode 100644 index 000000000000..aa7fb349ba4d --- /dev/null +++ b/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt @@ -0,0 +1,32 @@ +--TEST-- +grapheme_strrpos() and grapheme_strripos() find overlapping matches with negative offsets +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +grapheme_strrpos: 1, 1, 1, 1, 0 +grapheme_strripos: 1, 1, 1, 1, 0 +grapheme_strrpos: 1, 1, 1, 1, 0 +grapheme_strripos: 1, 1, 1, 1, 0 +grapheme_strrpos: 1, 1, 1, 1, 0 +grapheme_strripos: 1, 1, 1, 1, 0 +grapheme_strrpos: 1, 1, 1, 1, 0 +grapheme_strripos: 1, 1, 1, 1, 0 +int(1) +int(3) +int(0)