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 @@ -57,6 +57,8 @@ PHP NEWS
(Ilia Alshanetsky)
. Fixed Collator attribute and strength methods not rejecting an
unconstructed Collator. (Ilia Alshanetsky)
. Fixed grapheme_strstr() and grapheme_stristr() returning incorrect substrings
when supplementary characters precede the match. (Weilin Du)

- Lexbor:
. Merge patches lexbor/lexbor@8a14bc0 and lexbor/lexbor@f67ce4b, fixing a
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/grapheme/grapheme_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
if(char_pos != USEARCH_DONE && ubrk_isBoundary(bi, char_pos)) {
ret_pos = grapheme_count_graphemes(bi, uhaystack,char_pos);
if(puchar_pos) {
*puchar_pos = char_pos;
*puchar_pos = u_countChar32(uhaystack, char_pos);
}
} else {
ret_pos = -1;
Expand Down
27 changes: 27 additions & 0 deletions ext/intl/tests/grapheme_strstr_supplementary_prefix.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
grapheme_strstr() and grapheme_stristr() preserve match boundaries after supplementary characters
--EXTENSIONS--
intl
--FILE--
<?php
foreach (["\u{1F600}", "\u{1F600}\u{1F600}", "\u{1F600}e\u{0301}"] as $prefix) {
$haystack = $prefix . 'abc';
var_dump(grapheme_strstr($haystack, 'a'));
var_dump(grapheme_strstr($haystack, 'a', true));
var_dump(grapheme_stristr($haystack, 'A'));
var_dump(grapheme_stristr($haystack, 'A', true));
}
?>
--EXPECT--
string(3) "abc"
string(4) "😀"
string(3) "abc"
string(4) "😀"
string(3) "abc"
string(8) "😀😀"
string(3) "abc"
string(8) "😀😀"
string(3) "abc"
string(7) "😀é"
string(3) "abc"
string(7) "😀é"
Loading