Bug #78245 [NEW]: preg_split('/\R/', 'Техни') wrongly splits text into 2 parts

From: Date: Wed, 03 Jul 2019 13:50:06 +0000
Subject: Bug #78245 [NEW]: preg_split('/\R/', 'Техни') wrongly splits text into 2 parts
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221621@lists.php.net to get a copy of this message
From: bugs_php at zarevak dot net Operating system: any (tested Windows, Linux) PHP version: 7.3.6 Package: PCRE related Bug Type: Bug Bug description:preg_split('/\R/', 'Техни') wrongly splits text into 2 parts Description: ------------ According to https://www.php.net/manual/en/regexp.reference.escape.php the \R should match line-breaks (\n, \r and \r\n), but here it matches something else and breaks the string into two. When using expression \r\n|\n|\r directly, it works correctly. Adding 'u' pattern modifier fixes the issue, but checks validity of the incoming UTF-8 string, which I do not want. The Russian text 'Техни' in this example does not contain \r or \n characters even when encoded using UTF-8 so this should not apply. The \R splits the string in the middle of the 'х' (U+0445 CYRILLIC SMALL LETTER HA) character, which is encoded in UTF-8 as bytes #D1 #85. This is either bug: 1] in implementation of \R, where it incorrectly matches different bytes then 13, 10 and their combination 2] or in documentation, where it should state what other characters it can match (in this example it seems, it matches U+0085 <control> : NEXT LINE [NEL]) Test script: --------------- <?php $string="Реконструкция\r\nРеконструкция - Служба Технической поддержки\r\n"; $array = preg_split('/\R/', $string); // BUG! $array2 = preg_split('/\r\n|\n|\r/', $string); //OK :) var_dump($array, $array2, ($array===$array2)); Expected result: ---------------- array(3) { [0]=> string(26) "Реконструкция" [1]=> string(83) "Реконструкция - Служба Технической поддержки" [2]=> string(0) "" } array(3) { [0]=> string(26) "Реконструкция" [1]=> string(83) "Реконструкция - Служба Технической поддержки" [2]=> string(0) "" } bool(true) Actual result: -------------- array(4) { [0]=> string(26) "Реконструкция" [1]=> string(47) "Реконструкция - Служба Те" [2]=> string(35) "нической поддержки" [3]=> string(0) "" } array(3) { [0]=> string(26) "Реконструкция" [1]=> string(83) "Реконструкция - Служба Технической поддержки" [2]=> string(0) "" } bool(false) -- Edit bug report at https://bugs.php.net/bug.php?id=78245&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78245&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78245&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78245&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=78245&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78245&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78245&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78245&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78245&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78245&r=support Expected behavior: https://bugs.php.net/fix.php?id=78245&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78245&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78245&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78245&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78245&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=78245&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78245&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78245&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78245&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78245&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78245&r=mysqlcfg

« previous php.bugs (#221621) next »