Page MenuHomePhabricator

Fix malformed escape sequences in MediaWiki's regexes for PHP 8 upgrade
Open, Needs TriagePublic

Description

PHP 8.0 no longer sets the PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL option, so is more strict about invalid regular expressions than PHP 7.3 and 7.4 (which set this option by default for backward compatibility). The UPGRADING file says:

- PCRE:
  . When passing invalid escape sequences they are no longer intepreted as
    literals. This behaviour previously required the X modifier - which is
    now ignored.

For example, '/\\?PHPUnit\\Framework\\TestCase/' is a "valid" regexp in PHP 7, but in PHP 8 it causes preg_match(): Compilation failed: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u. Because '\\' is a single backslash, actually 4 are needed to match a literal \ .

Event Timeline

Change 581512 had a related patch set uploaded (by MaxSem; owner: MaxSem):
[mediawiki/core@master] StructureTest: use proper escapes for PCRE2 compatibility

https://gerrit.wikimedia.org/r/581512

Change 581512 merged by jenkins-bot:
[mediawiki/core@master] phpunit: Simplify StructureTest

https://gerrit.wikimedia.org/r/581512

Anything automated we can do to scan regexes to work out what we need to update?

PleaseStand renamed this task from Make MediaWiki ready for PCRE2 to Fix malformed escape sequences in MediaWiki's regexes for PHP 8 upgrade.Oct 24 2022, 4:33 AM
PleaseStand updated the task description. (Show Details)