Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ext/intl/grapheme/grapheme_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
grapheme_strrpos() and grapheme_strripos() find overlapping matches with negative offsets
--EXTENSIONS--
intl
--FILE--
<?php
foreach (['a', "\u{00E9}", "e\u{0301}", "\u{1F600}"] as $grapheme) {
foreach (['grapheme_strrpos', 'grapheme_strripos'] as $function) {
$positions = [];
foreach ([0, 1, -1, -2, -3] as $offset) {
$positions[] = $function(str_repeat($grapheme, 3), str_repeat($grapheme, 2), $offset);
}
echo $function, ': ', implode(', ', $positions), "\n";
}
}

var_dump(grapheme_strripos("\u{00C9}\u{00E9}\u{00C9}", "\u{00E9}\u{00E9}", -1));
var_dump(grapheme_strrpos("\u{00E9}\u{00E9}x\u{00E9}\u{00E9}", "\u{00E9}\u{00E9}", -1));
var_dump(grapheme_strrpos("\u{00E9}\u{00E9}x\u{00E9}\u{00E9}", "\u{00E9}\u{00E9}", -3));
?>
--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)
Loading