php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76033 some words, preg_match_all can't match big S correctly
Submitted: 2018-03-01 03:29 UTC Modified: 2018-03-08 13:52 UTC
From: master at hiroz dot cn Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.6.33 OS: macOS 10.12.6
Private report: No CVE-ID: None
 [2018-03-01 03:29 UTC] master at hiroz dot cn
Description:
------------
preg_match_all can't match \S correctly

in php5.4 ~ php5.6.33

```
$matches = array();
$template = '<p>{{{ 发货单号 }}}</p><p>{{{ 单据123号 }}}</p><p>{{{ 拉包 }}}</p><p>{{{ a }}}</p><p>{{{ a }}}</p>';
$ret = preg_match_all('/\{\{\{ \S+ \}\}\}/', $template, $matches);
print_r($matches);
```

result is 
```
Array
(
    [0] => Array
        (
            [0] => {{{ 发货单号 }}}
            [1] => {{{ 单据123号 }}}
            [2] => {{{ a }}}
            [3] => {{{ a }}}
        )

)
```

the "拉包" is missing. i try many cases. "包" can't be matched by "\S".

but in php5.3 or other languages, "包" can be matched by "\S".




Test script:
---------------
$matches = array();
$template = '<p>{{{ 发货单号 }}}</p><p>{{{ 单据123号 }}}</p><p>{{{ 拉包 }}}</p><p>{{{ a }}}</p><p>{{{ a }}}</p>';
$ret = preg_match_all('/\{\{\{ \S+ \}\}\}/', $template, $matches);
print_r($matches);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => {{{ 发货单号 }}}
            [1] => {{{ 单据123号 }}}
            [2] => {{{ 拉包 }}}
            [3] => {{{ a }}}
            [4] => {{{ a }}}
        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => {{{ 发货单号 }}}
            [1] => {{{ 单据123号 }}}
            [2] => {{{ a }}}
            [3] => {{{ a }}}
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-01 12:03 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: PCRE related
 [2018-03-01 12:03 UTC] cmb@php.net
I cannot reproduce the described behavior:
<https://3v4l.org/UeP92>.
 [2018-03-01 13:12 UTC] master at hiroz dot cn
please try it in macOS again.
 [2018-03-06 18:12 UTC] jhdxr@php.net
I cannot reproduce this bug as well.

In addition, did you try php 7.1 or above? 5.6 only received in security support.
 [2018-03-07 01:37 UTC] master at hiroz dot cn
I reproduce it in 5.4~5.6.33 in macOS. In Linux all versions works fine.

In macOS, 5.7 works fine too.

If these versions only received in security support, I think it can be ignored.
 [2018-03-07 01:38 UTC] master at hiroz dot cn
I wrote wrong in previous message.

I reproduce it in 5.4~5.6.33 in macOS. In Linux all versions works fine.

In macOS, 7.2 works fine too.

If these versions only received in security support, I think it can be ignored.
 [2018-03-08 13:52 UTC] jhdxr@php.net
-Status: Open +Status: Not a bug
 [2018-03-08 13:52 UTC] jhdxr@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Thanks for your report, and I'm closing this bug since it works in the latest release. 

btw, [here](http://php.net/supported-versions.php) is the timetable for support versions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC