Bug #68310 [NEW]: preg_split() fail with extended modifier

From: Date: Mon, 27 Oct 2014 13:18:53 +0000
Subject: Bug #68310 [NEW]: preg_split() fail with extended modifier
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188322@lists.php.net to get a copy of this message
From: david dot proweb at gmail dot com Operating system: Irrelevant PHP version: 5.5.18 Package: PCRE related Bug Type: Bug Bug description:preg_split() fail with extended modifier Description: ------------ preg_split(pattern, subject) will fail if I use a pattern with extended (/x) modifier with escaped sequences (like \r or \n), but if I double escape it, it'll work. Seems a bug for me. If I do: /\r?\n/ over "abc\r\n123" it will split to ["abc", "123"]. If I do: /\r?\n/x over "abc\r\n123" it will will fail¹. If I do: /\\r?\\n/x over "abc\r\n123" it will split to ["abc", "123"]. If you repair, I need to escape twice when I use /x modifier. It doesn't occur if I use preg_match(pattern, subject). PHP 4.x it'll works correctly. ¹ Compilation failed: nothing to repeat at offset 1. Test script: --------------- $split_normal = "/\r?\n/"; $split_extended_escaped = "/\r?\n/x"; $split_extended_reescaped = "/\\r?\\n/x"; $split_text = "abc\r\n123"; var_dump(preg_split($split_normal, $split_text)); // OK var_dump(preg_split($split_extended_escaped, $split_text)); // Wrongly FAIL var_dump(preg_split($split_extended_reescaped, $split_text)); // Wrongly OK -- Edit bug report at https://bugs.php.net/bug.php?id=68310&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68310&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68310&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68310&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68310&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68310&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68310&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68310&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68310&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68310&r=support Expected behavior: https://bugs.php.net/fix.php?id=68310&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68310&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68310&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68310&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68310&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68310&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68310&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68310&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68310&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68310&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68310&r=mysqlcfg

« previous php.bugs (#188322) next »