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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ PHP NEWS
left busy for the next fetch, and rows delivered from a result another
statement took over. (KentarouTakeda)

- Intl:
. Fixed grapheme_strrev() treating UBRK_DONE as a byte index and leaving
the result without a terminating NUL. (iliaal)

- Phar:
. Fixed Phar archives being automatically detected when ".phar" only occurs
in a directory name or is not a filename extension in an included file's
Expand Down
4 changes: 4 additions & 0 deletions ext/intl/grapheme/grapheme_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,13 +1175,17 @@ U_CFUNC PHP_FUNCTION(grapheme_strrev)
current = ZSTR_LEN(string);
for (end = pstr; pos != UBRK_DONE; ) {
pos = ubrk_previous(bi);
if (pos == UBRK_DONE) {
break;
}
end_len = current - pos;
for (int32_t j = 0; j < end_len; j++) {
*p++ = *(pstr + pos + j);
}
current = pos;
}
ubrk_end:
ZSTR_VAL(ret)[ZSTR_LEN(ret)] = '\0';
RETVAL_NEW_STR(ret);
ubrk_close(bi);
close:
Expand Down
25 changes: 25 additions & 0 deletions ext/intl/tests/grapheme_strrev_ubrk_done.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
grapheme_strrev() stops at UBRK_DONE instead of using it as a byte index
--EXTENSIONS--
intl
--FILE--
<?php

$cases = [
'abc',
'a',
'土下座',
"null\x00byte",
];

foreach ($cases as $s) {
$rev = grapheme_strrev($s);
echo strlen($s), ' ', strlen($rev), ' ', bin2hex($rev), "\n";
}

?>
--EXPECT--
3 3 636261
1 1 61
9 9 e5baa7e4b88be59c9f
9 9 65747962006c6c756e
Loading