#42945 [Ver->Csd]: preg_split() swallows part of the string
| From: | nlopess@php.net | Date: | Sun, 13 Jan 2008 14:44:38 +0000 |
| Subject: | #42945 [Ver->Csd]: preg_split() swallows part of the string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121242@lists.php.net to get a copy of this message | ||
ID: 42945
Updated by: nlopess@php.net
Reported By: Arne dot Heizmann at csr dot com
-Status: Verified
+Status: Closed
Bug Type: PCRE related
Operating System: *
PHP Version: 5CVS-2007-10-22
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2008-01-12 02:16:40] felipe@php.net
I tested in PHP 5.3
Index: php_pcre.c
===================================================================
RCS file: /repository/php-src/ext/pcre/php_pcre.c,v
retrieving revision 1.168.2.9.2.21.2.8
diff -u -r1.168.2.9.2.21.2.8 php_pcre.c
--- php_pcre.c 31 Dec 2007 07:17:11 -0000 1.168.2.9.2.21.2.8
+++ php_pcre.c 12 Jan 2008 02:14:13 -0000
@@ -1562,7 +1562,7 @@
}
- if (!no_empty || start_offset != subject_len)
+ if (!no_empty || last_match[0] != '\0')
{
if (offset_capture) {
/* Add the last (match, offset) pair to the
return value */
------------------------------------------------------------------------
[2007-10-22 08:52:08] jani@php.net
Verified using latest CVS snapshot.
------------------------------------------------------------------------
[2007-10-12 12:04:43] Arne dot Heizmann at csr dot com
Description:
------------
The following example code shows how preg_split() - when used with
PREG_SPLIT_NO_EMPTY - omits pieces which aren't empty. The returned
array SHOULD contain ALL of the characters from the original string
minus the characters that match the separator. In my example, the
separator is a zero-width match.
I notice that this problem was reported as Bug #15413 before and marked
"Bogus". My example shows that the bug is real.
Reproduce code:
---------------
<?
header ('Content-type: text/plain');
var_export (preg_split ('/\b/', 'a\'', -1, PREG_SPLIT_NO_EMPTY));
?>
Expected result:
----------------
array (
0 => 'a',
1 => '\'',
)
Actual result:
--------------
array (
0 => 'a',
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42945&edit=1