Bug #14173 Updated: preg_match incorrectly parses data with binary zero
| From: | andrei@php.net | Date: | Tue, 15 Jan 2002 15:41:02 +0000 |
| Subject: | Bug #14173 Updated: preg_match incorrectly parses data with binary zero | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-77137@lists.php.net to get a copy of this message | ||
ID: 14173
Updated by: andrei
Reported By: frog@enlight.ru
Old Status: Open
Status: Closed
Bug Type: PCRE related
Operating System: Win98
PHP Version: 4.0.6
New Comment:
Fixed in CVS - thanks.
Previous Comments:
------------------------------------------------------------------------
[2001-11-22 06:23:44] frog@enlight.ru
$data = "abc\0\0de"; # \0, \x00 - never mind
preg_match('/ab(.{4})e/s', $data, $res);
echo(bin2hex($data)); # 61626300006465
echo(bin2hex($res[0])); # 616263
echo(bin2hex($res[1])); # 63
PHP4.0.6/Win32 (binary distr.)
From PHP PCRE docs:
--------------
4. Though binary zero characters are supported in the subject string,
they are
not allowed in a pattern string because it is passed as a normal C
string,
terminated by zero. The escape sequence "\0" can be used in the pattern
to
represent a binary zero.
-----------
From original PCRE docs (http://www.pcre.org/man.txt):
--------
The subject string is passed as a pointer in subject, a
length in length, and a starting offset in startoffset.
Unlike the pattern string, the subject may contain binary
zero characters. When the starting offset is zero, the
search for a match starts at the beginning of the subject,
and this is by far the most common case.
---------
by the way, it seems that preg_replace() works correctly. Problems with
preg_match()
please report if i'm wrong and it isn't a bug.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14173&edit=1