Skip to content

Improve Parser backward compatibility #13310

@pento

Description

@pento

Describe the bug

The regular expression that the PHP parser uses the (?<name>pattern) syntax to create named subpatterns. This syntax was introduced in PHP 5.2.2.

$has_match = preg_match(
'/<!--\s+(?<closer>\/)?wp:(?<namespace>[a-z][a-z0-9_-]*\/)?(?<name>[a-z][a-z0-9_-]*)\s+(?<attrs>{(?:(?:[^}]+|}+(?=})|(?!}\s+\/?-->).)*+)?}\s+)?(?<void>\/)?-->/s',
$this->document,
$matches,
PREG_OFFSET_CAPTURE,
$this->offset
);

Strictly speaking, however, the syntax was introduced in PCRE 7.0, which is the default version of PCRE built into PHP 5.2.2, but some Linux distros (Centos 5 is a known example) use an older PCRE. In the case of Centos 5, they use PCRE 6.6.

In core (as well as in other places in Gutenberg), we've avoided this problem by using the older (?P<name>pattern) syntax.

I'd like to get this fixed in WordPress 5.1.

Ref: https://core.trac.wordpress.org/ticket/45644

Metadata

Metadata

Assignees

Labels

Backwards CompatibilityIssues or PRs that impact backwards compatability[Feature] ParsingRelated to efforts to improving the parsing of a string of data and converting it into a different f[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions