com php-src: Fix #65732: grapheme_*() is not Unicod e compliant on CR LF sequence: NEWS ext/intl/gr apheme/grapheme_util.c ext/intl/tests/bug65732
.phpt
| From: | Christoph Michael Becker | Date: | Sat, 20 Aug 2016 01:01:35 +0000 |
| Subject: | com php-src: Fix #65732: grapheme_*() is not Unicod e compliant on CR LF sequence: NEWS ext/intl/gr apheme/grapheme_util.c ext/intl/tests/bug65732 .phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94010@lists.php.net to get a copy of this message | ||
Commit: e4a006cd3e17338677ec269a8cdb1354f38e0cad
Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 19 Aug 2016 19:05:33 +0200
Parents: 9164dc11e2323b8b80c389bb13d70789799b44fc
Branches: PHP-5.6 PHP-7..0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e4a006cd3e17338677ec269a8cdb1354f38e0cad
Log:
Fix #65732: grapheme_*() is not Unicode compliant on CR LF sequence
According to the Unicode specification (at least as of 5.1), CRLF sequences
are considered to be a single grapheme. We cater to that special case by
letting grapheme_ascii_check() fail. While it would be trivial to fix
grapheme_ascii_check() wrt. grapheme_strlen(), grapheme_substr() and
grapheme_strrpos() would be much harder to handle, so we accept the slight
performance penalty if CRLF is involved.
Bugs:
https://bugs.php.net/65732
Changed paths:
M NEWS
M ext/intl/grapheme/grapheme_util.c
A ext/intl/tests/bug65732.phpt
Diff:
diff --git a/NEWS b/NEWS
index 013d85f..e1d7f04 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ PHP NEWS
- IMAP:
. Fixed bug #72852 (imap_mail null dereference). (Anatol)
+- Intl:
+ . Fixed bug #65732 (grapheme_*() is not Unicode compliant on CR LF
+ sequence). (cmb)
+
- JSON:
. Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c
index c752b02..350ba66 100644
--- a/ext/intl/grapheme/grapheme_util.c
+++ b/ext/intl/grapheme/grapheme_util.c
@@ -221,7 +221,7 @@ int grapheme_ascii_check(const unsigned char *day, int32_t len)
{
int ret_len = len;
while ( len-- ) {
- if ( *day++ > 0x7f )
+ if ( *day++ > 0x7f || (*day == '\n' && *(day - 1) == '\r') )
return -1;
}
diff --git a/ext/intl/tests/bug65732.phpt b/ext/intl/tests/bug65732.phpt
new file mode 100644
index 0000000..b49f884
--- /dev/null
+++ b/ext/intl/tests/bug65732.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #65732 (grapheme_*() is not Unicode compliant on CR LF sequence)
+--SKIPIF--
+<?php
+if (!extension_loaded('intl')) die('skip intl extension not available');
+?>
+--FILE--
+<?php
+var_dump(grapheme_strlen("\r\n"));
+var_dump(grapheme_substr(implode("\r\n", ['abc', 'def',
'ghi']), 5));
+var_dump(grapheme_strrpos("a\r\nb", 'b'));
+?>
+==DONE==
+--EXPECT--
+int(1)
+string(7) "ef
+ghi"
+int(2)
+==DONE==