php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77726 PCRE2 now supports NULs in patterns
Submitted: 2019-03-12 07:42 UTC Modified: 2019-03-13 04:19 UTC
From: 605036592 at qq dot com Assigned:
Status: Open Package: PCRE related
PHP Version: 7.2.16 OS: CentOS-7.4-x86_64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-03-12 07:42 UTC] 605036592 at qq dot com
Description:
------------
when I use preg_match pattern 0x0, Warning: preg_match(): Null byte in regex
regex has match all character, why php not allow 0x0? it's a bug or has any reason? 

Test script:
---------------
preg_match("/a".chr(0)."bc/", 'abc');

Expected result:
----------------
I expect preg_match right return 0 or 1 and not warning

Actual result:
--------------
Warning: preg_match(): Null byte in regex

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-12 08:15 UTC] requinix@php.net
-Summary: Warning: preg_match(): Null byte in regex +Summary: PCRE does not support NULs in patterns; PHP will warn -Type: Bug +Type: Documentation Problem -Package: PHP Language Specification +Package: PCRE related
 [2019-03-12 08:15 UTC] requinix@php.net
PCRE does not support NUL bytes inside pattern strings.

While not a major pain point, this should probably be documented. The introduction says they can't be delimiters, and the escape sequences page implies it when it mentions non-printing characters, but besides in the actual pcre.org docs linked to with a vague "some limitations" warning, I didn't see anywhere else that conclusively stated it.
 [2019-03-12 17:22 UTC] cmb@php.net
PCRE2 supports NUL bytes in patterns, so we may want to lift the
current restriction.  OTOH,

  preg_match('/a\\0bc/', 'abc')

already works as expected.
 [2019-03-13 04:16 UTC] 605036592 at qq dot com
hello cmb@php.net, I think "/a".chr(0)."bc/" != '/a\\0bc/', so not the same question!
 [2019-03-13 04:19 UTC] requinix@php.net
-Summary: PCRE does not support NULs in patterns; PHP will warn +Summary: PCRE2 now supports NULs in patterns -Type: Documentation Problem +Type: Bug
 [2019-03-13 04:19 UTC] requinix@php.net
I assume the restriction is purely technical, so if we can lift it with PCRE2 then that's probably the right answer.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 00:01:27 2019 UTC