Skip to content
Open
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 @@ -28,6 +28,8 @@ PHP NEWS
. Fixed Locale::parseLocale() reading past a trailing '-' or '_'.
(iliaal, Xuyang Zhang)
. Fixed grapheme_str_split() treating UBRK_DONE as a byte index. (iliaal)
. Fixed grapheme_strpos() and grapheme_strrpos() with an empty needle
returning UTF-16 offsets instead of grapheme offsets. (iliaal)

- Opcache:
. Fixed opcache.protect_memory race under ZTS. (realFlowControl)
Expand Down
6 changes: 5 additions & 1 deletion ext/intl/grapheme/grapheme_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
ret_pos = -1;
goto finish;
}
ret_pos = last && offset >= 0 ? uhaystack_len : offset_pos;
if (last && offset >= 0) {
ret_pos = grapheme_count_graphemes(bi, uhaystack, uhaystack_len);
} else {
ret_pos = grapheme_count_graphemes(bi, uhaystack, offset_pos);
}
goto finish;
}

Expand Down
36 changes: 36 additions & 0 deletions ext/intl/tests/grapheme_empty_offset_multibyte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
grapheme_strpos() family with empty needle and offset on multi-code-unit graphemes
--EXTENSIONS--
intl
--FILE--
<?php

ini_set("intl.error_level", E_WARNING);

var_dump(grapheme_strpos("😀x", ""));
var_dump(grapheme_strpos("😀x", "", 0));
var_dump(grapheme_strpos("😀x", "", 1));
var_dump(grapheme_stripos("😀x", "", 1));
var_dump(grapheme_strpos("😀x", "", -1));
var_dump(grapheme_strrpos("😀x", ""));
var_dump(grapheme_strrpos("😀x", "", 1));
var_dump(grapheme_strripos("😀x", "", 1));
var_dump(grapheme_strrpos("😀x", "", -1));
try {
var_dump(grapheme_strpos("😀x", "", 5));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
int(0)
int(0)
int(1)
int(1)
int(1)
int(2)
int(2)
int(2)
int(1)
grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
Loading