From fe54a7677596601be7cd110f2426ad9ed3ed6367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 16:57:19 +0100 Subject: [PATCH 1/9] Split REGEXP patterns into tokens to translate them The next commits translate ICU syntax that PCRE lacks, like nested sets, "\p{...}" names, and "\uhhhh" escapes, which span more than one character. Replace the escaping loop with one regex, which splits a pattern into quoted text, escapes, and other characters, and a table of their translations. The slash delimiter stays, so the output doesn't change. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 107 ++++++++++-------- .../tests/WP_MySQL_On_SQLite_Tests.php | 29 ++++- 2 files changed, 84 insertions(+), 52 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 91b40dea6..ac6c7576e 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -1328,7 +1328,7 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w } else { $newline = '(*ANY)'; } - $compiled = '/' . $newline . $this->regexp_escape_pattern( $pattern, $without_g ) . '/' . $modifiers; + $compiled = '/' . $newline . $this->regexp_translate_pattern( $pattern, $without_g ) . '/' . $modifiers; /* * Compile the pattern by matching it against an empty string. Only a compile @@ -1353,68 +1353,75 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w } /** - * Escape pattern delimiters and NUL bytes that are not already escaped, read - * "\K" as "K", and, if asked, make "\G" never match. + * Translate a MySQL regex pattern to PCRE syntax. * - * PHP before 8.2 rejects NUL bytes in patterns, so they become "\x00". + * Splits the pattern into quoted text, escapes, and other characters, so that a + * translation applies only to a whole token. * * @param string $pattern The regex pattern. - * @param bool $without_g Optional. Whether "\G" never matches. + * @param bool $without_g Whether "\G" never matches. * + * @throws Exception If the pattern can't be split. * @return string Pattern safe to wrap in slash delimiters. */ - private function regexp_escape_pattern( $pattern, $without_g = false ) { - $special = array( - '/' => '\\/', - "\0" => '\\x00', - ); + private function regexp_translate_pattern( $pattern, $without_g ) { + $tokens = array( + // The delimiter, and NUL bytes, which PHP before 8.2 rejects in patterns. + '/' => '\\/', + "\0" => '\\x00', + "\\\0" => '\\x00', - /* - * ICU reads "\K" as "K". In PCRE, "\K" moves the start of the match, even to - * before the place where the search started, like in "(?<=\Ka)". - */ - $escapes = $special + array( 'K' => 'K' ); + /* + * ICU reads "\K" as "K". In PCRE, "\K" moves the start of the match, even to + * before the place where the search started, like in "(?<=\Ka)". + */ + '\\K' => 'K', + ); if ( $without_g ) { // A position can't be both a word boundary and not one, so "\b\B" never // matches. Unlike "(?!)", it has no ")" to end a "(?#...)" comment. - $escapes['G'] = '\\b\\B'; + $tokens['\\G'] = '\\b\\B'; } - $escaped = ''; - $quoted = false; - $length = strlen( $pattern ); - for ( $i = 0; $i < $length; ++$i ) { - $character = $pattern[ $i ]; - if ( $quoted ) { - if ( '\\' === $character && $i + 1 < $length && 'E' === $pattern[ $i + 1 ] ) { - $escaped .= '\\E'; - $quoted = false; - ++$i; - } elseif ( isset( $special[ $character ] ) ) { - $escaped .= '\\E' . $special[ $character ] . '\\Q'; - } else { - $escaped .= $character; - } - continue; - } - if ( '\\' === $character && $i + 1 < $length ) { - $next = $pattern[ $i + 1 ]; - $escaped .= isset( $escapes[ $next ] ) ? $escapes[ $next ] : $character . $next; - $quoted = 'Q' === $next; - ++$i; - } elseif ( isset( $special[ $character ] ) ) { - $escaped .= $special[ $character ]; - } else { - $escaped .= $character; - } + $translated = preg_replace_callback( + '/\\\\Q.*?(?:\\\\E|\z)|\\\\.|[\/\0]/s', + function ( $parts ) use ( $tokens ) { + return $this->regexp_translate_token( $parts[0], $tokens ); + }, + $pattern + ); + + // Long quoted text can hit PCRE's backtrack limit, and an empty pattern would match + // everything. + if ( null === $translated ) { + $this->regexp_fail( $pattern ); } + return $translated; + } - // Close quoted text that runs to the end, so that a trailing backslash - // can't escape the delimiter. - if ( $quoted ) { - $escaped .= '\\E'; + /** + * Translate a token of a pattern. + * + * @param string $token The token. + * @param string[] $tokens Translations of tokens. + * + * @return string The PCRE equivalent. + */ + private function regexp_translate_token( $token, $tokens ) { + if ( '\\Q' === substr( $token, 0, 2 ) ) { + // Quoting can't hold the delimiter or NUL bytes, so they are escaped between + // two quotes. Quoted text that runs to the end gets an "\E", so that a trailing + // backslash can't escape the delimiter. + $quoted = strtr( + $token, + array( + '/' => '\\E\\/\\Q', + "\0" => '\\E\\x00\\Q', + ) + ); + return '\\E' === substr( $token, -2 ) ? $quoted : $quoted . '\\E'; } - return $escaped; + return $tokens[ $token ] ?? $token; } /** @@ -1558,8 +1565,8 @@ private function regexp_matches( $pattern, $match_type, $byte_mode, $subject, $o /* * Only PCRE's "\K" can start a match before the search, and then the next - * search would find the same match forever. The escaper reads "\K" as "K", - * but not after a "\Q" in a comment, which it reads as quoted text. + * search would find the same match forever. The translation reads "\K" as + * "K", except after a "\Q" in a comment. */ if ( $match[0][1] < $offset ) { throw new Exception( 'Invalid regular expression: ' . $pattern . '.' ); diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 615959486..c3e3ea9f9 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -827,6 +827,30 @@ public static function regexpUnterminatedQuoteCases() { ); } + public function testRegexpQuotedTextInExtendedMode() { + // Quoted spaces, tabs, and "#" stay literal in extended mode. + $this->assertQuery( + "SELECT + REGEXP_LIKE('a b', '^(?x)\\\\Qa b\\\\E\$') AS space, + REGEXP_LIKE('ab', '^(?x)\\\\Qa b\\\\E\$') AS no_space, + REGEXP_LIKE('a\tb', '^(?x)\\\\Qa\tb\\\\E\$') AS tab, + REGEXP_LIKE('a#b', '^(?x)\\\\Qa#b\\\\E\$') AS hash, + REGEXP_LIKE('a', '^(?x)\\\\Qa#b\\\\E') AS comment" + ); + $this->assertEquals( + array( + (object) array( + 'space' => '1', + 'no_space' => '0', + 'tab' => '1', + 'hash' => '1', + 'comment' => '0', + ), + ), + $this->last_result + ); + } + public function testRegexpLikeNumericOperands() { $this->assertQuery( 'SELECT REGEXP_LIKE(123, 2) AS r' ); $this->assertSame( '1', $this->last_result[0]->r ); @@ -1449,8 +1473,9 @@ public function testRegexpEscapedKInLookbehind() { * @dataProvider regexpQuoteInCommentCases */ public function testRegexpEscapedKAfterQuoteInComment( $sql, $pattern ) { - // The escaper reads a "\Q" in a comment as quoted text, so a later "\K" reaches - // PCRE. A match that starts before the search is then an error, not an endless loop. + // The translation reads a "\Q" in a comment as quoted text, so a later "\K" + // reaches PCRE. A match that starts before the search is then an error, not an + // endless loop. $this->assertQueryError( 'SELECT ' . sprintf( $sql, $this->engine->quote( $pattern ) ), "Invalid regular expression: $pattern." From df5ce0d6e684643c2a2fde32d0948e612689cee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 18:03:35 +0100 Subject: [PATCH 2/9] Ignore case in [:upper:] and [:lower:] by default With the u modifier, PCRE reads these classes case-sensitively even in a case-insensitive pattern. 'a' REGEXP '[[:upper:]]' returned 0, where MySQL returns 1. PCRE 10.44 and older read \p{Lu} and \p{Ll} the same way. Replace them with \p{L&} when the pattern ignores case. \p{L&} doesn't follow inline flags, so a pattern with "(?-i)" keeps PCRE's reading. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 41 +++++++++--- .../tests/WP_MySQL_On_SQLite_Tests.php | 63 +++++++++++++++++++ .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 12 ---- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 9 --- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 12 ---- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 12 ---- 6 files changed, 97 insertions(+), 52 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index ac6c7576e..825cc046d 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -1246,6 +1246,11 @@ private function regexp_check_match_type( $function_name, $match_type ) { * collation isn't known here. * - PCRE doesn't match "ß" with "ss" when ignoring case, `$` also matches * between CR and LF, and `(?P...)` is valid. + * - Inline case flags don't change `[:upper:]` and `[:lower:]`, or `\p{Lu}` and + * `\p{Ll}` on PCRE 10.44 and older: `(?i)[[:upper:]]` with the `c` flag keeps + * their case, and a `(?-i)` keeps it in the whole pattern. + * - When ignoring case, `[:upper:]`, `[:lower:]`, `\p{Lu}`, and `\p{Ll}` also match + * letters like "ĸ" or "ℓ", which have no other case. ICU leaves them out. * - `\G` in a lookbehind doesn't always match where it does in ICU. * - Data that isn't valid UTF-8 is matched byte by byte and case-sensitively, * like MySQL binary strings. Other binary values match as text, so case @@ -1328,7 +1333,7 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w } else { $newline = '(*ANY)'; } - $compiled = '/' . $newline . $this->regexp_translate_pattern( $pattern, $without_g ) . '/' . $modifiers; + $compiled = '/' . $newline . $this->regexp_translate_pattern( $pattern, ! $case_sensitive, $without_g ) . '/' . $modifiers; /* * Compile the pattern by matching it against an empty string. Only a compile @@ -1355,16 +1360,17 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w /** * Translate a MySQL regex pattern to PCRE syntax. * - * Splits the pattern into quoted text, escapes, and other characters, so that a - * translation applies only to a whole token. + * Splits the pattern into quoted text, escapes, POSIX classes, and other characters, + * so that a translation applies only to a whole token. * - * @param string $pattern The regex pattern. - * @param bool $without_g Whether "\G" never matches. + * @param string $pattern The regex pattern. + * @param bool $case_insensitive Whether the pattern ignores case by default. + * @param bool $without_g Whether "\G" never matches. * * @throws Exception If the pattern can't be split. * @return string Pattern safe to wrap in slash delimiters. */ - private function regexp_translate_pattern( $pattern, $without_g ) { + private function regexp_translate_pattern( $pattern, $case_insensitive, $without_g ) { $tokens = array( // The delimiter, and NUL bytes, which PHP before 8.2 rejects in patterns. '/' => '\\/', @@ -1383,8 +1389,29 @@ private function regexp_translate_pattern( $pattern, $without_g ) { $tokens['\\G'] = '\\b\\B'; } + /* + * With the "u" modifier, PCRE reads [:upper:] and [:lower:] case-sensitively + * even when the pattern ignores case, where ICU matches both cases. PCRE 10.44 + * and older read \p{Lu} and \p{Ll} the same way. \p{L&} would ignore "(?-i)", so + * a pattern with it keeps PCRE's classes. + */ + if ( $case_insensitive && ! preg_match( '/\(\?[a-zA-Z]*-[a-zA-Z]*i/', $pattern ) ) { + $tokens += array( + '[:upper:]' => '\\p{L&}', + '[:^upper:]' => '\\P{L&}', + '[:lower:]' => '\\p{L&}', + '[:^lower:]' => '\\P{L&}', + '\\p{Lu}' => '\\p{L&}', + '\\P{Lu}' => '\\P{L&}', + '\\p{Ll}' => '\\p{L&}', + '\\P{Ll}' => '\\P{L&}', + ); + } + + // A property name stops at a backslash, so that a long run of "\p{" doesn't + // scan the rest of the pattern each time. $translated = preg_replace_callback( - '/\\\\Q.*?(?:\\\\E|\z)|\\\\.|[\/\0]/s', + '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?\w+:\]|\\\\[pP]\{[^}\\\\]*\}|\\\\.|[\/\0]/s', function ( $parts ) use ( $tokens ) { return $this->regexp_translate_token( $parts[0], $tokens ); }, diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index c3e3ea9f9..0aa7eb905 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -1566,6 +1566,69 @@ public function testRegexpBigIntegerColumn() { ); } + /** + * @dataProvider regexpPosixCaseClassCases + */ + public function testRegexpPosixCaseClasses( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpPosixCaseClassCases() { + return array( + // Without the "c" flag, the classes ignore case, like in MySQL. + 'upper, lowercase' => array( "REGEXP_LIKE('a', '[[:upper:]]')", '1' ), + 'lower, uppercase' => array( "REGEXP_LIKE('A', '[[:lower:]]')", '1' ), + 'upper, non-ASCII' => array( "REGEXP_LIKE('é', '[[:upper:]]')", '1' ), + 'lower, non-ASCII' => array( "REGEXP_LIKE('É', '[[:lower:]]')", '1' ), + 'upper, digit' => array( "REGEXP_LIKE('1', '[[:upper:]]')", '0' ), + 'negated class' => array( "REGEXP_LIKE('a', '[[:^upper:]]')", '0' ), + 'negated class, digit' => array( "REGEXP_LIKE('1', '[[:^upper:]]')", '1' ), + 'negated set' => array( "REGEXP_LIKE('a', '[^[:upper:]]')", '0' ), + 'with other set members' => array( "REGEXP_LIKE('a', '^[[:upper:]0-9]\$')", '1' ), + 'outside of a set' => array( "REGEXP_LIKE('a', '[:upper:]')", '1' ), + 'REGEXP_REPLACE' => array( "REGEXP_REPLACE('abC', '[[:lower:]]', 'x')", 'xxx' ), + 'REGEXP_SUBSTR' => array( "REGEXP_SUBSTR('abc1', '[[:upper:]]+')", 'abc' ), + 'REGEXP_INSTR' => array( "REGEXP_INSTR('1a', '[[:upper:]]')", '2' ), + 'operator' => array( "'a' REGEXP '[[:upper:]]'", '1' ), + 'negated operator' => array( "'a' NOT REGEXP '[[:upper:]]'", '0' ), + + // So do the matching Unicode properties. + '\\p{Lu}, lowercase' => array( "REGEXP_LIKE('a', '\\\\p{Lu}')", '1' ), + '\\p{Ll}, uppercase' => array( "REGEXP_LIKE('A', '\\\\p{Ll}')", '1' ), + '\\p{Lu}, non-ASCII' => array( "REGEXP_LIKE('é', '\\\\p{Lu}')", '1' ), + '\\p{Lu}, digit' => array( "REGEXP_LIKE('1', '\\\\p{Lu}')", '0' ), + '\\P{Lu}, lowercase' => array( "REGEXP_LIKE('a', '\\\\P{Lu}')", '0' ), + '\\P{Lu}, digit' => array( "REGEXP_LIKE('1', '\\\\P{Lu}')", '1' ), + '\\p{Lu} in a set' => array( "REGEXP_LIKE('a', '[\\\\p{Lu}]')", '1' ), + '\\p{Lu} in a negated set' => array( "REGEXP_LIKE('a', '[^\\\\p{Lu}]')", '0' ), + '\\p{Lu}, REGEXP_REPLACE' => array( "REGEXP_REPLACE('aB1', '\\\\p{Lu}', 'x')", 'xx1' ), + '\\p{Ll}, operator' => array( "'A' REGEXP '\\\\p{Ll}'", '1' ), + '\\p{Lu}, c flag' => array( "REGEXP_LIKE('a', '\\\\p{Lu}', 'c')", '0' ), + '\\p{Lu}, inline flag' => array( "REGEXP_LIKE('a', '(?-i)\\\\p{Lu}')", '0' ), + 'quoted \\p{Lu}' => array( "REGEXP_LIKE('a', '\\\\Q\\\\p{Lu}\\\\E')", '0' ), + 'escaped backslash' => array( "REGEXP_LIKE('\\\\p{Lu}', '^\\\\\\\\p\\\\{Lu\\\\}\$')", '1' ), + + // With the "c" flag, the classes keep their case. + 'c flag, upper' => array( "REGEXP_LIKE('A', '[[:upper:]]', 'c')", '1' ), + 'c flag, other case' => array( "REGEXP_LIKE('a', '[[:upper:]]', 'c')", '0' ), + 'c flag, lower other case' => array( "REGEXP_LIKE('A', '[[:lower:]]', 'c')", '0' ), + + // So they do with "(?-i)", which is how the REGEXP operator matches case. + 'inline flag, upper' => array( "REGEXP_LIKE('A', '(?-i)[[:upper:]]')", '1' ), + 'inline flag, other case' => array( "REGEXP_LIKE('a', '(?-i)[[:upper:]]')", '0' ), + 'inline flag in a group' => array( "REGEXP_LIKE('a', '(?-i:[[:upper:]])')", '0' ), + 'inline flag among others' => array( "REGEXP_LIKE('a', '(?s-i)[[:upper:]]')", '0' ), + 'inline flag, operator' => array( "'a' REGEXP '(?-i)[[:upper:]]'", '0' ), + + // Escaped and quoted text is not a class. + 'escaped bracket' => array( "REGEXP_LIKE('[:upper:]', '^\\\\[:upper:]\$')", '1' ), + 'escaped bracket, letter' => array( "REGEXP_LIKE('a', '^\\\\[:upper:]\$')", '0' ), + 'quoted class' => array( "REGEXP_LIKE('[:upper:]', '^\\\\Q[:upper:]\\\\E\$')", '1' ), + 'quoted class, letter' => array( "REGEXP_LIKE('a', '\\\\Q[:upper:]\\\\E')", '0' ), + ); + } + public function testInsertDateNow() { $this->assertQuery( "INSERT INTO _dates (option_name, option_value) VALUES ('first', now());" diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index 64f1c94c6..b651da75a 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -988,18 +988,6 @@ protected function get_known_failures(): array { ); } - // Since PCRE2 10.45, a caseless \p{Lu} matches any cased letter, like ICU. - if ( version_compare( $pcre_version, '10.45', '<' ) ) { - array_push( - $failures, - 'icu-regextst:41', - 'icu-regextst:43', - 'icu-regextst:189', - 'icu-regextst:1061', - 'icu-regextst:1063' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index 0e7b7a362..0fb46de46 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -947,15 +947,6 @@ protected function get_known_failures(): array { ); } - // Since PCRE2 10.45, a caseless \p{Lu} matches any cased letter, like ICU. - if ( version_compare( $pcre_version, '10.45', '<' ) ) { - array_push( - $failures, - 'icu-regextst:41', - 'icu-regextst:43' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index 4eae03f59..f245cf6df 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -1021,18 +1021,6 @@ protected function get_known_failures(): array { ); } - // Since PCRE2 10.45, a caseless \p{Lu} matches any cased letter, like ICU. - if ( version_compare( $pcre_version, '10.45', '<' ) ) { - array_push( - $failures, - 'icu-regextst:41', - 'icu-regextst:43', - 'icu-regextst:189', - 'icu-regextst:1061', - 'icu-regextst:1063' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index ae48e3237..491683e35 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -988,18 +988,6 @@ protected function get_known_failures(): array { ); } - // Since PCRE2 10.45, a caseless \p{Lu} matches any cased letter, like ICU. - if ( version_compare( $pcre_version, '10.45', '<' ) ) { - array_push( - $failures, - 'icu-regextst:41', - 'icu-regextst:43', - 'icu-regextst:189', - 'icu-regextst:1061', - 'icu-regextst:1063' - ); - } - return $failures; } } From a50fdb5f04a58d61106d170fc45224b30df5f45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 18:04:15 +0100 Subject: [PATCH 3/9] Exclude ASCII symbols from [:punct:] PCRE's [:punct:] also holds ASCII symbols such as + $ = ~, where ICU's holds Unicode punctuation only. REGEXP_REPLACE('a+b.c$d', '[[:punct:]]', '') removed all of them, where MySQL keeps + and $. Replace the class with \p{P}. It also applies to byte-oriented matching, where MySQL reads bytes as Latin-1, so 0xAB counts as punctuation. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 12 ++++-- .../tests/WP_MySQL_On_SQLite_Tests.php | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 825cc046d..3f810c550 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -1373,15 +1373,19 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w private function regexp_translate_pattern( $pattern, $case_insensitive, $without_g ) { $tokens = array( // The delimiter, and NUL bytes, which PHP before 8.2 rejects in patterns. - '/' => '\\/', - "\0" => '\\x00', - "\\\0" => '\\x00', + '/' => '\\/', + "\0" => '\\x00', + "\\\0" => '\\x00', + + // PCRE's [:punct:] also holds ASCII symbols like "+", where ICU's doesn't. + '[:punct:]' => '\\p{P}', + '[:^punct:]' => '\\P{P}', /* * ICU reads "\K" as "K". In PCRE, "\K" moves the start of the match, even to * before the place where the search started, like in "(?<=\Ka)". */ - '\\K' => 'K', + '\\K' => 'K', ); if ( $without_g ) { // A position can't be both a word boundary and not one, so "\b\B" never diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 0aa7eb905..e8e5f056e 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -1629,6 +1629,44 @@ public static function regexpPosixCaseClassCases() { ); } + /** + * @dataProvider regexpPosixPunctCases + */ + public function testRegexpPosixPunct( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpPosixPunctCases() { + return array( + // ICU's class holds Unicode punctuation only, without ASCII symbols. + 'ASCII punctuation' => array( "REGEXP_LIKE('.', '[[:punct:]]')", '1' ), + 'plus' => array( "REGEXP_LIKE('+', '[[:punct:]]')", '0' ), + 'dollar' => array( "REGEXP_LIKE('\$', '[[:punct:]]')", '0' ), + 'equals' => array( "REGEXP_LIKE('=', '[[:punct:]]')", '0' ), + 'tilde' => array( "REGEXP_LIKE('~', '[[:punct:]]')", '0' ), + 'non-ASCII punctuation' => array( "REGEXP_LIKE('«', '[[:punct:]]')", '1' ), + 'non-ASCII symbol' => array( "REGEXP_LIKE('€', '[[:punct:]]')", '0' ), + 'c flag' => array( "REGEXP_LIKE('+', '[[:punct:]]', 'c')", '0' ), + 'negated class' => array( "REGEXP_LIKE('.', '[[:^punct:]]')", '0' ), + 'negated class, symbol' => array( "REGEXP_LIKE('+', '[[:^punct:]]')", '1' ), + 'with other set members' => array( "REGEXP_LIKE('+', '^[[:punct:]+]\$')", '1' ), + 'outside of a set' => array( "REGEXP_LIKE('.', '[:punct:]')", '1' ), + 'REGEXP_REPLACE' => array( "REGEXP_REPLACE('a+b.c\$d,e=f!g', '[[:punct:]]', '')", 'a+bc$de=fg' ), + 'operator, punctuation' => array( "'.' REGEXP '[[:punct:]]'", '1' ), + 'operator, symbol' => array( "'+' REGEXP '[[:punct:]]'", '0' ), + 'quoted class' => array( "REGEXP_LIKE('.', '\\\\Q[:punct:]\\\\E')", '0' ), + ); + } + + public function testRegexpPosixPunctOnBinaryData() { + // Bytes that are not valid UTF-8 are read as Latin-1, where 0xAB is "«". + $this->assertQuery( 'CREATE TABLE blobs (id INT PRIMARY KEY, b BLOB)' ); + $this->assertQuery( "INSERT INTO blobs VALUES (1, X'2BFF'), (2, X'2EFF'), (3, X'AB')" ); + $this->assertQuery( "SELECT b REGEXP '[[:punct:]]' AS r FROM blobs ORDER BY id" ); + $this->assertSame( array( '0', '1', '1' ), array_column( $this->last_result, 'r' ) ); + } + public function testInsertDateNow() { $this->assertQuery( "INSERT INTO _dates (option_name, option_value) VALUES ('first', now());" From 1844b396558079e792ce83b9db22eab8d95e05c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 17:02:20 +0100 Subject: [PATCH 4/9] Translate ICU sets with nested sets and set operations ICU sets can nest, and they subtract and intersect with "--" and "&&", or with a single "-" or "&" between two sets. PCRE has none of this, so such patterns silently matched something else, or failed to compile. A POSIX class outside of a set, which ICU reads as a set, failed too, and so did a hyphen after a class, like in "[\w-.]", which ICU reads literally. Parse each set, and translate its operations to lookaheads, like "(?:(?![aeiou])[a-z])". A set without operations stays a PCRE class. The rules come from MySQL 8.4's results. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 241 ++++++++++++++++- .../tests/WP_MySQL_On_SQLite_Tests.php | 175 +++++++++++- .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 256 +----------------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 246 ----------------- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 256 +----------------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 256 +----------------- 6 files changed, 406 insertions(+), 1024 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 3f810c550..fdaa12654 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -1238,9 +1238,9 @@ private function regexp_check_match_type( $function_name, $match_type ) { * (UTF-8) modifier is applied unless byte-oriented matching is requested. * Case-insensitive is the default. * - * MySQL uses ICU, which differs from PCRE in some syntax, like ICU-only escapes - * and nested sets. The known failures of the REGEXP test suites list these - * cases. Other known differences: + * MySQL uses ICU, which differs from PCRE in some syntax, like ICU-only escapes. + * The known failures of the REGEXP test suites list these cases. Other known + * differences: * * - Text matching ignores case unless the `c` flag is passed, as the column * collation isn't known here. @@ -1251,6 +1251,9 @@ private function regexp_check_match_type( $function_name, $match_type ) { * their case, and a `(?-i)` keeps it in the whole pattern. * - When ignoring case, `[:upper:]`, `[:lower:]`, `\p{Lu}`, and `\p{Ll}` also match * letters like "ĸ" or "ℓ", which have no other case. ICU leaves them out. + * - When ignoring case, ICU applies it to a set after the set's operations, so + * `[A-Za-z--aeiou]` matches "a", as "A" stays in the set. Here, the operation + * removes both cases. Operands in brackets, like `[a-z--[aeiou]]`, match ICU. * - `\G` in a lookbehind doesn't always match where it does in ICU. * - Data that isn't valid UTF-8 is matched byte by byte and case-sensitively, * like MySQL binary strings. Other binary values match as text, so case @@ -1360,14 +1363,14 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w /** * Translate a MySQL regex pattern to PCRE syntax. * - * Splits the pattern into quoted text, escapes, POSIX classes, and other characters, - * so that a translation applies only to a whole token. + * Splits the pattern into quoted text, sets, escapes, POSIX classes, and other + * characters, so that a translation applies only to a whole token. * * @param string $pattern The regex pattern. * @param bool $case_insensitive Whether the pattern ignores case by default. * @param bool $without_g Whether "\G" never matches. * - * @throws Exception If the pattern can't be split. + * @throws Exception If the pattern can't be split, or it has an invalid set. * @return string Pattern safe to wrap in slash delimiters. */ private function regexp_translate_pattern( $pattern, $case_insensitive, $without_g ) { @@ -1412,12 +1415,30 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $without ); } - // A property name stops at a backslash, so that a long run of "\p{" doesn't - // scan the rest of the pattern each time. + /* + * A set, with its nested sets, is one token, as ICU's sets differ from PCRE's. + * Like ICU, "[:" starts a POSIX class if the next ":" is followed by "]", and a + * set otherwise. ICU reads a POSIX class outside of a set, as in "[:alpha:]", as + * a set. The set's loops and its leading "^" and "]" are possessive, so that a + * long set doesn't exhaust PCRE's stack, and the "]" of "[]" or "[^]" can't end + * the set. + * + * A property name stops at a backslash, so that a long run of "\p{" doesn't + * scan the rest of the pattern each time. A control escape, like "\c[", takes + * the next character, unless it is the delimiter or a NUL byte, which need + * escaping. + */ $translated = preg_replace_callback( - '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?\w+:\]|\\\\[pP]\{[^}\\\\]*\}|\\\\.|[\/\0]/s', - function ( $parts ) use ( $tokens ) { - return $this->regexp_translate_token( $parts[0], $tokens ); + '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?[^:]*:\]|(\[\^?+\]?+(?:\\\\Q.*?(?:\\\\E|\z)|\\\\c[^\/\0]|\\\\.|\[:\^?[^:]*:\]|(?1)|[^\\\\\[\]])*+\])|\\\\[pP]\{[^}\\\\]*\}|\\\\c[^\/\0]|\\\\.|[\/\0]/s', + function ( $parts ) use ( $pattern, $tokens ) { + $token = $parts[0]; + if ( isset( $parts[1] ) ) { + return $this->regexp_translate_set( $token, $pattern, $tokens ); + } + if ( '[' === $token[0] ) { + return '[' . ( $tokens[ $token ] ?? $token ) . ']'; + } + return $this->regexp_translate_token( $token, $tokens ); }, $pattern ); @@ -1430,6 +1451,204 @@ function ( $parts ) use ( $tokens ) { return $translated; } + /** + * Translate an ICU set, like "[a-z--[aeiou]]", to PCRE. + * + * ICU sets can nest, and they have operations that PCRE classes lack. "--" and "&&" + * subtract or intersect the items up to the next of them. A single "-" or "&" between + * two sets applies the second set to all the items before it, back to the start or + * the last "--" or "&&". Class escapes and properties right after the second set + * join it. Elsewhere, "-" and "&" are literal, unless "-" makes a range. A set + * without operations stays a PCRE class, and the others become lookaheads, like + * "(?:(?![aeiou])[a-z])". + * + * @param string $set The set, with its brackets. + * @param string $pattern The regex pattern, for error messages. + * @param string[] $tokens Translations of tokens. + * + * @throws Exception If ICU rejects the set. + * @return string The PCRE equivalent, which matches one character. + */ + private function regexp_translate_set( $set, $pattern, $tokens ) { + // An escape with its argument is one token, and so is a character, also when the + // set isn't valid UTF-8. + preg_match_all( + '/\\\\Q.*?(?:\\\\E|\z)|\\\\(?:[pP](?:\{[^}\\\\]*\}|\w)|x(?:\{[^}\\\\]*\}|[0-9a-fA-F]{1,2})|N\{[^}\\\\]*\}|c[^\/\0]|.)|\[:\^?[^:]*:\]|\[\^?|&&|--|[\xC0-\xFF][\x80-\xBF]*|./s', + $set, + $parts + ); + + // ICU reads quoted text one character at a time, so a quoted character can end a + // range and start the next one, and empty quotes leave nothing. + $characters = array(); + foreach ( $parts[0] as $part ) { + if ( '\\Q' !== substr( $part, 0, 2 ) ) { + $characters[] = $part; + continue; + } + preg_match_all( '/[\xC0-\xFF][\x80-\xBF]*|./s', substr( $part, 2, -2 ), $quoted ); + foreach ( $quoted[0] as $character ) { + $characters[] = '\\Q' . $character . '\\E'; + } + } + $position = 0; + return $this->regexp_set_fragment( $this->regexp_parse_set( $characters, $position, $pattern, $tokens ) ); + } + + /** + * Parse an ICU set from its tokens. + * + * @param string[] $parts The tokens of the set. + * @param int $position The position of the set's "[" or "[^", moved past its "]". + * @param string $pattern The regex pattern, for error messages. + * @param string[] $tokens Translations of tokens. + * + * @throws Exception If ICU rejects the set. + * @return array The set, as array( PCRE class body or fragment, whether it's a class body ). + */ + private function regexp_parse_set( array $parts, &$position, $pattern, $tokens ) { + // An escape is translated, and another character is escaped if PCRE needs it. + $literal = function ( $part ) use ( $tokens ) { + return '\\' === $part[0] ? $this->regexp_translate_token( $part, $tokens ) : ( $tokens[ $part ] ?? preg_quote( $part ) ); + }; + + $negated = '[^' === $parts[ $position++ ]; + $result = null; + $operator = null; + $terms = array(); + $type = null; // The kind of the last term. + $pending = null; // A single "-" or "&" to apply, with the items before it. + for ( $first = true; ; $first = false ) { + $part = $parts[ $position++ ] ?? null; + $next = $parts[ $position ] ?? ''; + + // Like in ICU, class escapes and properties right after the second set of a + // single "-" or "&" join that set. Anything else applies the operation first. + if ( $pending && ! preg_match( '/^\\\\[pPdDsSwWhHvV]/', (string) $part ) ) { + $terms = array( $this->regexp_set_operation( $pending[0], $pending[1], $this->regexp_set_union( $terms ) ) ); + $pending = null; + } + + // ICU reads "]" right after "[" or "[^" literally. + if ( null === $part || ( ']' === $part && ! $first ) ) { + if ( null === $part || ! $terms ) { + throw new Exception( "Invalid regular expression: $pattern." ); + } + break; + } + if ( '--' === $part || '&&' === $part ) { + if ( ! $terms ) { + throw new Exception( "Invalid regular expression: $pattern." ); + } + $right = $this->regexp_set_union( $terms ); + $result = null === $result ? $right : $this->regexp_set_operation( $result, $operator, $right ); + $operator = $part; + $terms = array(); + $type = null; + continue; + } + + // A single "-" or "&" between two sets applies to all the items before it. + if ( ( '-' === $part || '&' === $part ) && 'set' === $type && '[' === substr( $next, 0, 1 ) ) { + if ( '[:' === substr( $next, 0, 2 ) ) { + $right = array( $tokens[ $next ] ?? $next, true ); + ++$position; + } else { + $right = $this->regexp_parse_set( $parts, $position, $pattern, $tokens ); + } + $pending = array( $this->regexp_set_union( $terms ), '-' === $part ? '--' : '&&' ); + $terms = array( $right ); + continue; + } + + // A "-" between two characters makes a range. A class escape or a property + // can't end it. + if ( '-' === $part && 'literal' === $type && ! in_array( $next, array( '', ']', '--', '&&' ), true ) && '[' !== $next[0] ) { + if ( preg_match( '/^\\\\[pPdDsSwWhHvV]/', $next ) ) { + throw new Exception( "Invalid regular expression: $pattern." ); + } + $last = count( $terms ) - 1; + $terms[ $last ] = array( $terms[ $last ][0] . '-' . $literal( $next ), true ); + $type = 'range'; + ++$position; + continue; + } + + if ( '[' === $part[0] && '[:' !== substr( $part, 0, 2 ) ) { + --$position; + $terms[] = $this->regexp_parse_set( $parts, $position, $pattern, $tokens ); + $type = 'set'; + } elseif ( preg_match( '/^(?:\[:|\\\\[pP])/', $part ) ) { + $terms[] = array( $tokens[ $part ] ?? $part, true ); + $type = 'set'; + } elseif ( preg_match( '/^\\\\[dDsSwWhHvV]$/', $part ) ) { + $terms[] = array( $part, true ); + $type = 'escape'; + } else { + $terms[] = array( $literal( $part ), true ); + $type = 'literal'; + } + } + + $right = $this->regexp_set_union( $terms ); + $set = null === $result ? $right : $this->regexp_set_operation( $result, $operator, $right ); + if ( ! $negated ) { + return $set; + } + return array( $set[1] ? '[^' . $set[0] . ']' : '(?:(?!' . $set[0] . ')[\\s\\S])', false ); + } + + /** + * Join the terms of a set into one class, or into alternatives if a term isn't a class. + * + * @param array[] $terms The terms, as returned by regexp_parse_set(). + * + * @return array The union, as array( PCRE class body or fragment, whether it's a class body ). + */ + private function regexp_set_union( array $terms ) { + $body = ''; + $alternatives = array(); + foreach ( $terms as $term ) { + if ( $term[1] ) { + $body .= $term[0]; + } else { + $alternatives[] = $term[0]; + } + } + if ( ! $alternatives ) { + return array( $body, true ); + } + if ( '' !== $body ) { + array_unshift( $alternatives, "[$body]" ); + } + return array( '(?:' . implode( '|', $alternatives ) . ')', false ); + } + + /** + * Subtract or intersect two sets. + * + * @param array $left The left set, as returned by regexp_parse_set(). + * @param string $operator "--" or "&&". + * @param array $right The right set. + * + * @return array The result, as a PCRE fragment. + */ + private function regexp_set_operation( array $left, $operator, array $right ) { + $assertion = '--' === $operator ? '(?!' : '(?='; + return array( '(?:' . $assertion . $this->regexp_set_fragment( $right ) . ')' . $this->regexp_set_fragment( $left ) . ')', false ); + } + + /** + * Get the PCRE fragment of a set. + * + * @param array $set The set, as returned by regexp_parse_set(). + * + * @return string The PCRE fragment, which matches one character. + */ + private function regexp_set_fragment( array $set ) { + return $set[1] ? "[{$set[0]}]" : $set[0]; + } + /** * Translate a token of a pattern. * diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index e8e5f056e..931ec4b3b 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -589,7 +589,7 @@ public function testRegexpLegacyOperatorUtf8Handling() { public function testRegexpNulBytePattern() { // A pattern starting with a NUL byte is an ordinary case-insensitive pattern. - // NUL bytes also match in quoted text and after a backslash. + // NUL bytes also match in quoted text, after a backslash, and in sets. $this->assertQuery( 'CREATE TABLE nul_patterns (id INT PRIMARY KEY, s TEXT, p TEXT)' ); $this->assertQuery( "INSERT INTO nul_patterns VALUES @@ -597,7 +597,9 @@ public function testRegexpNulBytePattern() { (2, 'aBc', X'0062'), (3, 'abc', 'B'), (4, X'61002F62', CONCAT('\\\\Qa', X'00', '/b\\\\E')), - (5, X'610062', CONCAT('a\\\\', X'00', 'B'))" + (5, X'610062', CONCAT('a\\\\', X'00', 'B')), + (6, X'610062', CONCAT('[', X'00', ']')), + (7, X'610062', CONCAT('[\\\\Q', X'00', '\\\\E]'))" ); $this->assertQuery( 'SELECT @@ -645,6 +647,20 @@ public function testRegexpNulBytePattern() { 'like_matched' => '1', 'position' => '1', ), + (object) array( + 'matched' => '1', + 'not_matched' => '0', + 'binary_matched' => '1', + 'like_matched' => '1', + 'position' => '2', + ), + (object) array( + 'matched' => '1', + 'not_matched' => '0', + 'binary_matched' => '1', + 'like_matched' => '1', + 'position' => '2', + ), ), $this->last_result ); @@ -1566,6 +1582,158 @@ public function testRegexpBigIntegerColumn() { ); } + /** + * @dataProvider regexpSetCases + */ + public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { + $this->assertQuery( + sprintf( + "SELECT REGEXP_REPLACE(%s, %s, '<\$0>', 1, 0, 'c') AS r", + $this->engine->quote( $subject ), + $this->engine->quote( $pattern ) + ) + ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpSetCases() { + return array( + // Nested sets are unions. + 'nested set' => array( '[a[b]]', 'abc', 'c' ), + 'nested range' => array( '[a-c[b]]', 'abcd', 'd' ), + 'nested negated set' => array( '[a[^b]]', 'abc', 'b' ), + 'negated union' => array( '[^a[^b]]', 'abc', 'ac' ), + '"]" first' => array( '[]a]', ']ab', '<]>b' ), + '"]" first, negated' => array( '[^]a]', ']ab', ']a' ), + '":" first' => array( '[:\w]+', 'a:b c', ' ' ), + '":" first, then a POSIX class' => array( '[:[:alpha:]]', 'a:1', '<:>1' ), + '"[:" without ":]"' => array( '[:a:b]', 'xab:', 'x<:>' ), + + // "--" and "&&" apply to the items up to the next of them, from left to right. + 'difference' => array( '[a-z--[b]--[c]]', 'abcd-', 'bc-' ), + 'difference of characters' => array( '[a-z--b--c]', 'abcd-', 'bc-' ), + 'difference of all items' => array( '[[a-c]--[b]x]', 'abcx', 'bx' ), + 'intersection' => array( '[\w&&[a-c]]', 'abd-', 'd-' ), + 'intersection of all items' => array( '[[a-c]&&[b]x]', 'abcx', 'acx' ), + 'intersection, then difference' => array( '[a-z&&[a-m]--c]', 'abcdn-', 'cn-' ), + 'difference, then intersection' => array( '[[a-z]--[b]&&[a-c]]', 'abcd-', 'bd-' ), + 'negated intersection' => array( '[^[a-c]&&[b-d]]', 'abcd', 'bc' ), + 'empty intersection' => array( '[a&&b]', 'ab', 'ab' ), + 'class escapes' => array( '[\w--\d]', 'a1_', '1<_>' ), + 'POSIX classes' => array( '[[:alpha:]&&[:upper:]]', 'aBc', 'ac' ), + 'literal "&" after "&&"' => array( '[&abcd&&&ac]', 'bac&&cad', 'b<&><&>d' ), + 'literal "-" after "--"' => array( '[-abcd---]', 'abc--', '--' ), + + // A single "-" or "&" between two sets applies to all the items before it. Class + // escapes and properties right after the second set join that set. + 'single "-" between sets' => array( '[[a-m]-[f-w]p]', 'depfgwxyz', '

fgwxyz' ), + 'single "-", chained' => array( '[[a-z]-[aeiou]-[xyz]]', 'abex-', 'aex-' ), + 'single "-" in an operand' => array( '[a-z--[b]-[c]]', 'abcd-', 'b-' ), + 'single "-" after a property' => array( '[\p{L}-[:digit:]]', 'a-5', '-5' ), + 'single "-" after a POSIX class' => array( '[[:digit:]-[:alpha:]]', '0-z', '<0>-z' ), + 'single "&" between sets' => array( '[[a-m]&[e-s]w]', 'efmwadnst', 'adnst' ), + 'single "&" after a property' => array( '[\p{L}&[a]]', 'ab&', 'b&' ), + 'single "-" after a union' => array( '[a[b]-[a]]', 'ab', 'a' ), + 'single "-" after a union of sets' => array( '[[a][b]-[a][c]]', 'abc', 'a' ), + 'single "&" after a union' => array( '[x[a-m]&[e-s]]', 'xaf', 'xa' ), + 'class escape after a single "-"' => array( '[[a-z]-[aeiou]\d]', 'ba1', 'a1' ), + 'class escape after a single "&"' => array( '[[a-z]&[a-m]\d]', 'bn1', 'n1' ), + 'property after a single "-"' => array( '[[a-z]-[aeiou]\p{Nd}]', 'ba1', 'a1' ), + '"-" after a joined property' => array( '[[a-z]-[aeiou]\p{Nd}-[b]]', 'bc1', 'b1' ), + 'letter after a joined escape' => array( '[[a-z]-[aeiou]\d1]', '12b', '<1>2' ), + 'POSIX class after a single "-"' => array( '[[a-z]-[aeiou][:digit:]]', 'a1b', 'a<1>' ), + + // Elsewhere, "-" and "&" are literal, unless "-" makes a range. + '"-" after a class escape' => array( '[\w-[0-9]]', 'a-5_', '<-><5><_>' ), + '"-" before a property' => array( '[\p{L}-\p{N}]', 'a-5', '<-><5>' ), + '"-" after a set, before a letter' => array( '[[a]-b]', 'ab-', '<->' ), + '"-" after a letter, before a set' => array( '[ab-[c]]', 'abc-', '<->' ), + '"-" after a letter, after a set' => array( '[[a]b-[b]]', 'ab-', '<->' ), + '"-" after a letter, before POSIX' => array( '[a-[:digit:]]', 'za-9', 'z<-><9>' ), + '"-" after a POSIX class' => array( '[[:digit:]-z]', '0-z=', '<0><->=' ), + '"-" after a range' => array( '[a-c-e]', 'abcde-', 'd<->' ), + '"-" first and last' => array( '[-a]', 'a-b', '<->b' ), + '"-" after "^"' => array( '[^-a]', '-ab', '-a' ), + '"&" between a set and a letter' => array( '[[a]&b]', 'ab&', '<&>' ), + '"&" between a letter and a set' => array( '[abcd&[ac]]', 'bd&x', '<&>x' ), + '"&" before a class escape' => array( '[[a-c]&\w]', 'abd-&', '-<&>' ), + '"&" last' => array( '[a-z&]', 'a&', '<&>' ), + 'escaped bracket' => array( '[\[a]', '[a', '<[>' ), + 'escaped hyphen' => array( '[a\-z]', 'a-zb', '<->b' ), + 'hex range' => array( '[\x{41}-\x{43}]', 'ABCD', 'D' ), + 'quoted bracket' => array( '[\Qa]\E]', ']a', '<]>' ), + 'empty quotes' => array( '[\W\Q\E]', 'a:', 'a<:>' ), + 'empty quotes outside of a set' => array( '(a)\1\Q\E0', 'aa0', '' ), + 'empty quotes before "-"' => array( '[\Q\E-\w]', 'a-', '<->' ), + 'empty quotes after a set' => array( '[[a]\Q\E-z]', 'am-z', 'm<->' ), + 'empty quotes before a set' => array( '[[a]-\Q\E[b]]', 'ab-', 'b-' ), + 'quotes that end a range' => array( '[a-\Qbc\E-z]', 'cm-', '-' ), + 'slash' => array( '[/a]', '/ab', 'b' ), + 'quoted slash' => array( '[\Q/\E]', 'a/', 'a' ), + 'slash in a difference' => array( '[[/a]--[a]]', '/a', 'a' ), + 'long set' => array( '[' . str_repeat( 'ab', 10000 ) . ']+', 'xab', 'x' ), + '"[]" in an extended comment' => array( "(?x)a # []\nb", 'ab', '' ), + '"[^]" in an extended comment' => array( "(?x)a # [^]\nb", 'ab', '' ), + '"\\c[" in a set' => array( '[\c[]', "a\e", "a<\e>" ), + '"\\c]" in a set' => array( '[\c]]', "a\x1D", "a<\x1D>" ), + + // A POSIX class outside of a set is a set. + 'POSIX class outside of a set' => array( '[:alpha:]+', 'ab1', '1' ), + 'negated POSIX class' => array( '[:^alpha:]', 'a1', 'a<1>' ), + 'POSIX class after a letter' => array( 'x[:alpha:]', 'xa', '' ), + + // Sets in lookbehinds. + 'negated union in a lookbehind' => array( '(?a<>b<>c<>' ), + 'empty set in a lookbehind' => array( '(?a<>b<>c<>' ), + ); + } + + /** + * @dataProvider regexpInvalidSetCases + */ + public function testRegexpInvalidSets( $pattern ) { + $this->assertQueryError( + sprintf( "SELECT REGEXP_LIKE('a', %s)", $this->engine->quote( $pattern ) ), + "Invalid regular expression: $pattern." + ); + } + + public static function regexpInvalidSetCases() { + return array( + 'empty set' => array( '[]' ), + 'empty negated set' => array( '[^]' ), + '"--" first' => array( '[--]' ), + '"&&" first' => array( '[&&a]' ), + '"--" last' => array( '[a--]' ), + '"&&" last' => array( '[a-z&&]' ), + '"--" first in a nested set' => array( '[abc[--def]]' ), + 'range to a class escape' => array( '[a-\w]' ), + 'POSIX class with a comma' => array( '[[:,:]]' ), + 'POSIX class with an escape' => array( '[:\w:]' ), + 'only empty quotes' => array( '[\Q\E]' ), + ); + } + + /** + * @dataProvider regexpSetIgnoreCaseCases + */ + public function testRegexpSetsIgnoreCase( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpSetIgnoreCaseCases() { + // Without the "c" flag, set operations ignore case, also in their operands. + return array( + 'difference' => array( "REGEXP_LIKE('B', '^[a-z--[aeiou]]\$')", '1' ), + 'difference, removed' => array( "REGEXP_LIKE('A', '^[a-z--[aeiou]]\$')", '0' ), + 'intersection' => array( "REGEXP_LIKE('b', '^[a-z&&[A-C]]\$')", '1' ), + 'intersection, removed' => array( "REGEXP_LIKE('D', '^[a-z&&[A-C]]\$')", '0' ), + 'single "-"' => array( "REGEXP_LIKE('b', '^[[a-z]-[B]]\$')", '0' ), + 'negated difference' => array( "REGEXP_LIKE('E', '^[^a-z--[aeiou]]\$')", '1' ), + ); + } + /** * @dataProvider regexpPosixCaseClassCases */ @@ -1587,6 +1755,8 @@ public static function regexpPosixCaseClassCases() { 'negated set' => array( "REGEXP_LIKE('a', '[^[:upper:]]')", '0' ), 'with other set members' => array( "REGEXP_LIKE('a', '^[[:upper:]0-9]\$')", '1' ), 'outside of a set' => array( "REGEXP_LIKE('a', '[:upper:]')", '1' ), + 'set difference' => array( "REGEXP_LIKE('a', '^[[:upper:]--[b]]\$')", '1' ), + 'set difference, removed' => array( "REGEXP_LIKE('b', '^[[:upper:]--[b]]\$')", '0' ), 'REGEXP_REPLACE' => array( "REGEXP_REPLACE('abC', '[[:lower:]]', 'x')", 'xxx' ), 'REGEXP_SUBSTR' => array( "REGEXP_SUBSTR('abc1', '[[:upper:]]+')", 'abc' ), 'REGEXP_INSTR' => array( "REGEXP_INSTR('1a', '[[:upper:]]')", '2' ), @@ -1602,6 +1772,7 @@ public static function regexpPosixCaseClassCases() { '\\P{Lu}, digit' => array( "REGEXP_LIKE('1', '\\\\P{Lu}')", '1' ), '\\p{Lu} in a set' => array( "REGEXP_LIKE('a', '[\\\\p{Lu}]')", '1' ), '\\p{Lu} in a negated set' => array( "REGEXP_LIKE('a', '[^\\\\p{Lu}]')", '0' ), + '\\p{Lu}, intersection' => array( "REGEXP_LIKE('a', '^[\\\\p{Lu}&&[a-c]]\$')", '1' ), '\\p{Lu}, REGEXP_REPLACE' => array( "REGEXP_REPLACE('aB1', '\\\\p{Lu}', 'x')", 'xx1' ), '\\p{Ll}, operator' => array( "'A' REGEXP '\\\\p{Ll}'", '1' ), '\\p{Lu}, c flag' => array( "REGEXP_LIKE('a', '\\\\p{Lu}', 'c')", '0' ), diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index b651da75a..5f91e237f 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -16,54 +16,6 @@ protected function get_known_failures(): array { $failures = array( 'mysql-server-suite:7923', 'mysql-server-suite:7924', - 'mysql-server-suite:9591', - 'mysql-server-suite:9592', - 'mysql-server-suite:9593', - 'mysql-server-suite:9594', - 'mysql-server-suite:9595', - 'mysql-server-suite:9596', - 'mysql-server-suite:9597', - 'mysql-server-suite:9598', - 'mysql-server-suite:9599', - 'mysql-server-suite:9600', - 'mysql-server-suite:9601', - 'mysql-server-suite:9602', - 'mysql-server-suite:9603', - 'mysql-server-suite:9604', - 'mysql-server-suite:9605', - 'mysql-server-suite:9606', - 'mysql-server-suite:9607', - 'mysql-server-suite:9608', - 'mysql-server-suite:9609', - 'mysql-server-suite:9610', - 'mysql-server-suite:9611', - 'mysql-server-suite:9612', - 'mysql-server-suite:9613', - 'mysql-server-suite:9614', - 'mysql-server-suite:9615', - 'mysql-server-suite:9616', - 'mysql-server-suite:9643', - 'mysql-server-suite:9644', - 'mysql-server-suite:9647', - 'mysql-server-suite:9648', - 'mysql-server-suite:9649', - 'mysql-server-suite:9650', - 'mysql-server-suite:9651', - 'mysql-server-suite:9652', - 'mysql-server-suite:9653', - 'mysql-server-suite:9654', - 'mysql-server-suite:9655', - 'mysql-server-suite:9656', - 'mysql-server-suite:9657', - 'mysql-server-suite:9658', - 'mysql-server-suite:9659', - 'mysql-server-suite:9660', - 'mysql-server-suite:9661', - 'mysql-server-suite:9662', - 'mysql-server-suite:9665', - 'mysql-server-suite:9666', - 'mysql-server-suite:9667', - 'mysql-server-suite:9668', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -238,20 +190,6 @@ protected function get_known_failures(): array { 'icu-regextst:384', 'icu-regextst:385', 'icu-regextst:386', - 'icu-regextst:387', - 'icu-regextst:388', - 'icu-regextst:389', - 'icu-regextst:390', - 'icu-regextst:391', - 'icu-regextst:392', - 'icu-regextst:393', - 'icu-regextst:394', - 'icu-regextst:395', - 'icu-regextst:396', - 'icu-regextst:397', - 'icu-regextst:398', - 'icu-regextst:399', - 'icu-regextst:400', 'icu-regextst:520', 'icu-regextst:521', 'icu-regextst:522', @@ -276,8 +214,6 @@ protected function get_known_failures(): array { 'icu-regextst:581', 'icu-regextst:582', 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -308,10 +244,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:931', - 'icu-regextst:932', - 'icu-regextst:933', - 'icu-regextst:934', 'icu-regextst:935', 'icu-regextst:936', 'icu-regextst:941', @@ -320,79 +252,20 @@ protected function get_known_failures(): array { 'icu-regextst:950', 'icu-regextst:951', 'icu-regextst:952', - 'icu-regextst:953', - 'icu-regextst:954', 'icu-regextst:963', 'icu-regextst:964', - 'icu-regextst:965', - 'icu-regextst:966', 'icu-regextst:967', 'icu-regextst:968', 'icu-regextst:969', 'icu-regextst:970', - 'icu-regextst:975', - 'icu-regextst:976', - 'icu-regextst:977', - 'icu-regextst:978', 'icu-regextst:979', 'icu-regextst:980', - 'icu-regextst:981', - 'icu-regextst:982', - 'icu-regextst:985', - 'icu-regextst:986', 'icu-regextst:993', 'icu-regextst:994', 'icu-regextst:995', 'icu-regextst:996', - 'icu-regextst:997', - 'icu-regextst:998', - 'icu-regextst:999', - 'icu-regextst:1000', - 'icu-regextst:1001', - 'icu-regextst:1002', - 'icu-regextst:1003', - 'icu-regextst:1004', - 'icu-regextst:1005', - 'icu-regextst:1006', - 'icu-regextst:1007', - 'icu-regextst:1008', - 'icu-regextst:1009', - 'icu-regextst:1010', - 'icu-regextst:1011', - 'icu-regextst:1012', - 'icu-regextst:1013', - 'icu-regextst:1014', - 'icu-regextst:1015', - 'icu-regextst:1016', - 'icu-regextst:1017', - 'icu-regextst:1018', 'icu-regextst:1019', - 'icu-regextst:1020', - 'icu-regextst:1021', - 'icu-regextst:1022', - 'icu-regextst:1023', - 'icu-regextst:1024', - 'icu-regextst:1025', - 'icu-regextst:1026', - 'icu-regextst:1027', - 'icu-regextst:1028', - 'icu-regextst:1031', - 'icu-regextst:1032', - 'icu-regextst:1034', - 'icu-regextst:1035', - 'icu-regextst:1036', - 'icu-regextst:1039', - 'icu-regextst:1040', - 'icu-regextst:1041', - 'icu-regextst:1042', - 'icu-regextst:1043', - 'icu-regextst:1044', - 'icu-regextst:1047', - 'icu-regextst:1048', - 'icu-regextst:1049', - 'icu-regextst:1050', - 'icu-regextst:1051', - 'icu-regextst:1052', + 'icu-regextst:1033', 'icu-regextst:1055', 'icu-regextst:1056', 'icu-regextst:1057', @@ -451,8 +324,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', 'icu-regextst:1135', 'icu-regextst:1136', 'icu-regextst:1137', @@ -467,8 +338,6 @@ protected function get_known_failures(): array { 'icu-regextst:1182', 'icu-regextst:1185', 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -697,129 +566,6 @@ protected function get_known_failures(): array { 'icu-regextst:3839', ); - // PCRE2 rejects a range with a class at one end, like "[\d-z]". PCRE 8 reads the "-" literally. - if ( $is_pcre2 ) { - array_push( - $failures, - 'mysql-server-suite:9539', - 'mysql-server-suite:9540', - 'mysql-server-suite:9541', - 'mysql-server-suite:9542', - 'mysql-server-suite:9543', - 'mysql-server-suite:9544', - 'mysql-server-suite:9545', - 'mysql-server-suite:9546', - 'mysql-server-suite:9547', - 'mysql-server-suite:9548', - 'mysql-server-suite:9549', - 'mysql-server-suite:9550', - 'mysql-server-suite:9551', - 'mysql-server-suite:9552', - 'mysql-server-suite:9553', - 'mysql-server-suite:9554', - 'mysql-server-suite:9555', - 'mysql-server-suite:9556', - 'mysql-server-suite:9557', - 'mysql-server-suite:9558', - 'mysql-server-suite:9559', - 'mysql-server-suite:9560', - 'mysql-server-suite:9561', - 'mysql-server-suite:9562', - 'mysql-server-suite:9563', - 'mysql-server-suite:9564', - 'mysql-server-suite:9565', - 'mysql-server-suite:9566', - 'mysql-server-suite:9567', - 'mysql-server-suite:9568', - 'mysql-server-suite:9569', - 'mysql-server-suite:9570', - 'mysql-server-suite:9571', - 'mysql-server-suite:9572', - 'mysql-server-suite:9573', - 'mysql-server-suite:9574', - 'mysql-server-suite:9575', - 'mysql-server-suite:9576', - 'mysql-server-suite:9577', - 'mysql-server-suite:9578', - 'mysql-server-suite:9579', - 'mysql-server-suite:9580', - 'mysql-server-suite:9581', - 'mysql-server-suite:9582', - 'mysql-server-suite:9583', - 'mysql-server-suite:9584', - 'mysql-server-suite:9585', - 'mysql-server-suite:9586', - 'mysql-server-suite:9587', - 'mysql-server-suite:9588', - 'mysql-server-suite:9589', - 'mysql-server-suite:9590', - 'mysql-server-suite:9617', - 'mysql-server-suite:9618', - 'mysql-server-suite:9619', - 'mysql-server-suite:9620', - 'mysql-server-suite:9621', - 'mysql-server-suite:9622', - 'mysql-server-suite:9623', - 'mysql-server-suite:9624', - 'mysql-server-suite:9625', - 'mysql-server-suite:9626', - 'mysql-server-suite:9627', - 'mysql-server-suite:9628', - 'mysql-server-suite:9629', - 'mysql-server-suite:9630', - 'mysql-server-suite:9631', - 'mysql-server-suite:9632', - 'mysql-server-suite:9633', - 'mysql-server-suite:9634', - 'mysql-server-suite:9635', - 'mysql-server-suite:9636', - 'mysql-server-suite:9637', - 'mysql-server-suite:9638', - 'mysql-server-suite:9639', - 'mysql-server-suite:9640', - 'mysql-server-suite:9641', - 'mysql-server-suite:9642', - 'mysql-server-suite:9645', - 'mysql-server-suite:9646', - 'mysql-server-suite:9663', - 'mysql-server-suite:9664', - 'icu-regextst:1037', - 'icu-regextst:1038', - 'icu-regextst:2460', - 'icu-regextst:2461', - 'icu-regextst:2462', - 'icu-regextst:2463', - 'icu-regextst:2464', - 'icu-regextst:2465', - 'icu-regextst:2466', - 'icu-regextst:2467', - 'icu-regextst:2468', - 'icu-regextst:2469', - 'icu-regextst:2470', - 'icu-regextst:2471', - 'icu-regextst:3892', - 'icu-regextst:3893', - 'icu-regextst:3894', - 'icu-regextst:3895', - 'icu-regextst:3896', - 'icu-regextst:3897', - 'icu-regextst:3898', - 'icu-regextst:3899', - 'icu-regextst:3900', - 'icu-regextst:3901', - 'icu-regextst:3902', - 'icu-regextst:3903' - ); - } - - // PCRE2 rejects a set difference after a class, like "[\w--b]". PCRE 8 reads the "-" literally, which gives MySQL's results here. - if ( $is_pcre2 ) { - array_push( - $failures, - 'icu-regextst:1033' - ); - } - // PCRE 8 rejects this nested lookbehind as not fixed in length. if ( ! $is_pcre2 ) { array_push( diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index 0fb46de46..1a57541b3 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -14,50 +14,6 @@ protected function get_known_failures(): array { // Cases that fail in every environment. $failures = array( - 'mysql-server-suite:9591', - 'mysql-server-suite:9592', - 'mysql-server-suite:9593', - 'mysql-server-suite:9594', - 'mysql-server-suite:9595', - 'mysql-server-suite:9596', - 'mysql-server-suite:9597', - 'mysql-server-suite:9598', - 'mysql-server-suite:9599', - 'mysql-server-suite:9600', - 'mysql-server-suite:9601', - 'mysql-server-suite:9602', - 'mysql-server-suite:9603', - 'mysql-server-suite:9604', - 'mysql-server-suite:9605', - 'mysql-server-suite:9606', - 'mysql-server-suite:9607', - 'mysql-server-suite:9608', - 'mysql-server-suite:9609', - 'mysql-server-suite:9610', - 'mysql-server-suite:9611', - 'mysql-server-suite:9612', - 'mysql-server-suite:9613', - 'mysql-server-suite:9614', - 'mysql-server-suite:9615', - 'mysql-server-suite:9616', - 'mysql-server-suite:9649', - 'mysql-server-suite:9650', - 'mysql-server-suite:9651', - 'mysql-server-suite:9652', - 'mysql-server-suite:9653', - 'mysql-server-suite:9654', - 'mysql-server-suite:9655', - 'mysql-server-suite:9656', - 'mysql-server-suite:9657', - 'mysql-server-suite:9658', - 'mysql-server-suite:9659', - 'mysql-server-suite:9660', - 'mysql-server-suite:9661', - 'mysql-server-suite:9662', - 'mysql-server-suite:9665', - 'mysql-server-suite:9666', - 'mysql-server-suite:9667', - 'mysql-server-suite:9668', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -232,20 +188,6 @@ protected function get_known_failures(): array { 'icu-regextst:384', 'icu-regextst:385', 'icu-regextst:386', - 'icu-regextst:387', - 'icu-regextst:388', - 'icu-regextst:389', - 'icu-regextst:390', - 'icu-regextst:391', - 'icu-regextst:392', - 'icu-regextst:393', - 'icu-regextst:394', - 'icu-regextst:395', - 'icu-regextst:396', - 'icu-regextst:397', - 'icu-regextst:398', - 'icu-regextst:399', - 'icu-regextst:400', 'icu-regextst:520', 'icu-regextst:521', 'icu-regextst:522', @@ -270,8 +212,6 @@ protected function get_known_failures(): array { 'icu-regextst:581', 'icu-regextst:582', 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -302,10 +242,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:931', - 'icu-regextst:932', - 'icu-regextst:933', - 'icu-regextst:934', 'icu-regextst:935', 'icu-regextst:936', 'icu-regextst:941', @@ -316,66 +252,16 @@ protected function get_known_failures(): array { 'icu-regextst:952', 'icu-regextst:963', 'icu-regextst:964', - 'icu-regextst:965', - 'icu-regextst:966', 'icu-regextst:967', 'icu-regextst:968', 'icu-regextst:969', 'icu-regextst:970', - 'icu-regextst:975', - 'icu-regextst:976', - 'icu-regextst:977', - 'icu-regextst:978', 'icu-regextst:979', 'icu-regextst:980', - 'icu-regextst:981', - 'icu-regextst:982', - 'icu-regextst:985', - 'icu-regextst:986', 'icu-regextst:993', 'icu-regextst:994', 'icu-regextst:995', 'icu-regextst:996', - 'icu-regextst:997', - 'icu-regextst:998', - 'icu-regextst:1001', - 'icu-regextst:1002', - 'icu-regextst:1003', - 'icu-regextst:1004', - 'icu-regextst:1005', - 'icu-regextst:1006', - 'icu-regextst:1007', - 'icu-regextst:1008', - 'icu-regextst:1009', - 'icu-regextst:1010', - 'icu-regextst:1011', - 'icu-regextst:1012', - 'icu-regextst:1015', - 'icu-regextst:1016', - 'icu-regextst:1017', - 'icu-regextst:1018', - 'icu-regextst:1019', - 'icu-regextst:1020', - 'icu-regextst:1021', - 'icu-regextst:1022', - 'icu-regextst:1023', - 'icu-regextst:1024', - 'icu-regextst:1027', - 'icu-regextst:1028', - 'icu-regextst:1031', - 'icu-regextst:1032', - 'icu-regextst:1035', - 'icu-regextst:1036', - 'icu-regextst:1039', - 'icu-regextst:1040', - 'icu-regextst:1043', - 'icu-regextst:1044', - 'icu-regextst:1047', - 'icu-regextst:1048', - 'icu-regextst:1049', - 'icu-regextst:1050', - 'icu-regextst:1051', - 'icu-regextst:1052', 'icu-regextst:1055', 'icu-regextst:1056', 'icu-regextst:1057', @@ -434,8 +320,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', 'icu-regextst:1135', 'icu-regextst:1136', 'icu-regextst:1137', @@ -450,8 +334,6 @@ protected function get_known_failures(): array { 'icu-regextst:1182', 'icu-regextst:1185', 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -668,134 +550,6 @@ protected function get_known_failures(): array { 'icu-regextst:3839', ); - // PCRE2 rejects a range with a class at one end, like "[\d-z]". PCRE 8 reads the "-" literally. - if ( $is_pcre2 ) { - array_push( - $failures, - 'mysql-server-suite:9539', - 'mysql-server-suite:9540', - 'mysql-server-suite:9541', - 'mysql-server-suite:9542', - 'mysql-server-suite:9543', - 'mysql-server-suite:9544', - 'mysql-server-suite:9545', - 'mysql-server-suite:9546', - 'mysql-server-suite:9547', - 'mysql-server-suite:9548', - 'mysql-server-suite:9549', - 'mysql-server-suite:9550', - 'mysql-server-suite:9551', - 'mysql-server-suite:9552', - 'mysql-server-suite:9553', - 'mysql-server-suite:9554', - 'mysql-server-suite:9555', - 'mysql-server-suite:9556', - 'mysql-server-suite:9557', - 'mysql-server-suite:9558', - 'mysql-server-suite:9559', - 'mysql-server-suite:9560', - 'mysql-server-suite:9561', - 'mysql-server-suite:9562', - 'mysql-server-suite:9563', - 'mysql-server-suite:9564', - 'mysql-server-suite:9565', - 'mysql-server-suite:9566', - 'mysql-server-suite:9567', - 'mysql-server-suite:9568', - 'mysql-server-suite:9569', - 'mysql-server-suite:9570', - 'mysql-server-suite:9571', - 'mysql-server-suite:9572', - 'mysql-server-suite:9573', - 'mysql-server-suite:9574', - 'mysql-server-suite:9575', - 'mysql-server-suite:9576', - 'mysql-server-suite:9577', - 'mysql-server-suite:9578', - 'mysql-server-suite:9579', - 'mysql-server-suite:9580', - 'mysql-server-suite:9581', - 'mysql-server-suite:9582', - 'mysql-server-suite:9583', - 'mysql-server-suite:9584', - 'mysql-server-suite:9585', - 'mysql-server-suite:9586', - 'mysql-server-suite:9587', - 'mysql-server-suite:9588', - 'mysql-server-suite:9589', - 'mysql-server-suite:9590', - 'mysql-server-suite:9617', - 'mysql-server-suite:9618', - 'mysql-server-suite:9619', - 'mysql-server-suite:9620', - 'mysql-server-suite:9621', - 'mysql-server-suite:9622', - 'mysql-server-suite:9623', - 'mysql-server-suite:9624', - 'mysql-server-suite:9625', - 'mysql-server-suite:9626', - 'mysql-server-suite:9627', - 'mysql-server-suite:9628', - 'mysql-server-suite:9629', - 'mysql-server-suite:9630', - 'mysql-server-suite:9631', - 'mysql-server-suite:9632', - 'mysql-server-suite:9633', - 'mysql-server-suite:9634', - 'mysql-server-suite:9635', - 'mysql-server-suite:9636', - 'mysql-server-suite:9637', - 'mysql-server-suite:9638', - 'mysql-server-suite:9639', - 'mysql-server-suite:9640', - 'mysql-server-suite:9641', - 'mysql-server-suite:9642', - 'mysql-server-suite:9643', - 'mysql-server-suite:9644', - 'mysql-server-suite:9645', - 'mysql-server-suite:9646', - 'mysql-server-suite:9647', - 'mysql-server-suite:9648', - 'mysql-server-suite:9663', - 'mysql-server-suite:9664', - 'icu-regextst:1037', - 'icu-regextst:1038', - 'icu-regextst:2460', - 'icu-regextst:2461', - 'icu-regextst:2462', - 'icu-regextst:2463', - 'icu-regextst:2464', - 'icu-regextst:2465', - 'icu-regextst:2466', - 'icu-regextst:2467', - 'icu-regextst:2468', - 'icu-regextst:2469', - 'icu-regextst:2470', - 'icu-regextst:2471', - 'icu-regextst:3892', - 'icu-regextst:3893', - 'icu-regextst:3894', - 'icu-regextst:3895', - 'icu-regextst:3896', - 'icu-regextst:3897', - 'icu-regextst:3898', - 'icu-regextst:3899', - 'icu-regextst:3900', - 'icu-regextst:3901', - 'icu-regextst:3902', - 'icu-regextst:3903' - ); - } - - // PCRE2 rejects a set difference after a class, like "[\w--b]". PCRE 8 reads the "-" literally, which gives MySQL's results here. - if ( $is_pcre2 ) { - array_push( - $failures, - 'icu-regextst:1033', - 'icu-regextst:1034' - ); - } - // PCRE 8 rejects this nested lookbehind as not fixed in length. if ( ! $is_pcre2 ) { array_push( diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index f245cf6df..ac5b96ebf 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -26,54 +26,6 @@ protected function get_known_failures(): array { 'mysql-server-suite:7924', 'mysql-server-suite:8349', 'mysql-server-suite:8350', - 'mysql-server-suite:9591', - 'mysql-server-suite:9592', - 'mysql-server-suite:9593', - 'mysql-server-suite:9594', - 'mysql-server-suite:9595', - 'mysql-server-suite:9596', - 'mysql-server-suite:9597', - 'mysql-server-suite:9598', - 'mysql-server-suite:9599', - 'mysql-server-suite:9600', - 'mysql-server-suite:9601', - 'mysql-server-suite:9602', - 'mysql-server-suite:9603', - 'mysql-server-suite:9604', - 'mysql-server-suite:9605', - 'mysql-server-suite:9606', - 'mysql-server-suite:9607', - 'mysql-server-suite:9608', - 'mysql-server-suite:9609', - 'mysql-server-suite:9610', - 'mysql-server-suite:9611', - 'mysql-server-suite:9612', - 'mysql-server-suite:9613', - 'mysql-server-suite:9614', - 'mysql-server-suite:9615', - 'mysql-server-suite:9616', - 'mysql-server-suite:9643', - 'mysql-server-suite:9644', - 'mysql-server-suite:9647', - 'mysql-server-suite:9648', - 'mysql-server-suite:9649', - 'mysql-server-suite:9650', - 'mysql-server-suite:9651', - 'mysql-server-suite:9652', - 'mysql-server-suite:9653', - 'mysql-server-suite:9654', - 'mysql-server-suite:9655', - 'mysql-server-suite:9656', - 'mysql-server-suite:9657', - 'mysql-server-suite:9658', - 'mysql-server-suite:9659', - 'mysql-server-suite:9660', - 'mysql-server-suite:9661', - 'mysql-server-suite:9662', - 'mysql-server-suite:9665', - 'mysql-server-suite:9666', - 'mysql-server-suite:9667', - 'mysql-server-suite:9668', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -252,20 +204,6 @@ protected function get_known_failures(): array { 'icu-regextst:384', 'icu-regextst:385', 'icu-regextst:386', - 'icu-regextst:387', - 'icu-regextst:388', - 'icu-regextst:389', - 'icu-regextst:390', - 'icu-regextst:391', - 'icu-regextst:392', - 'icu-regextst:393', - 'icu-regextst:394', - 'icu-regextst:395', - 'icu-regextst:396', - 'icu-regextst:397', - 'icu-regextst:398', - 'icu-regextst:399', - 'icu-regextst:400', 'icu-regextst:520', 'icu-regextst:521', 'icu-regextst:522', @@ -290,8 +228,6 @@ protected function get_known_failures(): array { 'icu-regextst:581', 'icu-regextst:582', 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -329,10 +265,6 @@ protected function get_known_failures(): array { 'icu-regextst:895', 'icu-regextst:896', 'icu-regextst:919', - 'icu-regextst:931', - 'icu-regextst:932', - 'icu-regextst:933', - 'icu-regextst:934', 'icu-regextst:935', 'icu-regextst:936', 'icu-regextst:941', @@ -341,79 +273,20 @@ protected function get_known_failures(): array { 'icu-regextst:950', 'icu-regextst:951', 'icu-regextst:952', - 'icu-regextst:953', - 'icu-regextst:954', 'icu-regextst:963', 'icu-regextst:964', - 'icu-regextst:965', - 'icu-regextst:966', 'icu-regextst:967', 'icu-regextst:968', 'icu-regextst:969', 'icu-regextst:970', - 'icu-regextst:975', - 'icu-regextst:976', - 'icu-regextst:977', - 'icu-regextst:978', 'icu-regextst:979', 'icu-regextst:980', - 'icu-regextst:981', - 'icu-regextst:982', - 'icu-regextst:985', - 'icu-regextst:986', 'icu-regextst:993', 'icu-regextst:994', 'icu-regextst:995', 'icu-regextst:996', - 'icu-regextst:997', - 'icu-regextst:998', - 'icu-regextst:999', - 'icu-regextst:1000', - 'icu-regextst:1001', - 'icu-regextst:1002', - 'icu-regextst:1003', - 'icu-regextst:1004', - 'icu-regextst:1005', - 'icu-regextst:1006', - 'icu-regextst:1007', - 'icu-regextst:1008', - 'icu-regextst:1009', - 'icu-regextst:1010', - 'icu-regextst:1011', - 'icu-regextst:1012', - 'icu-regextst:1013', - 'icu-regextst:1014', - 'icu-regextst:1015', - 'icu-regextst:1016', - 'icu-regextst:1017', - 'icu-regextst:1018', 'icu-regextst:1019', - 'icu-regextst:1020', - 'icu-regextst:1021', - 'icu-regextst:1022', - 'icu-regextst:1023', - 'icu-regextst:1024', - 'icu-regextst:1025', - 'icu-regextst:1026', - 'icu-regextst:1027', - 'icu-regextst:1028', - 'icu-regextst:1031', - 'icu-regextst:1032', - 'icu-regextst:1034', - 'icu-regextst:1035', - 'icu-regextst:1036', - 'icu-regextst:1039', - 'icu-regextst:1040', - 'icu-regextst:1041', - 'icu-regextst:1042', - 'icu-regextst:1043', - 'icu-regextst:1044', - 'icu-regextst:1047', - 'icu-regextst:1048', - 'icu-regextst:1049', - 'icu-regextst:1050', - 'icu-regextst:1051', - 'icu-regextst:1052', + 'icu-regextst:1033', 'icu-regextst:1055', 'icu-regextst:1056', 'icu-regextst:1057', @@ -472,8 +345,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', 'icu-regextst:1135', 'icu-regextst:1136', 'icu-regextst:1137', @@ -490,8 +361,6 @@ protected function get_known_failures(): array { 'icu-regextst:1182', 'icu-regextst:1185', 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -722,129 +591,6 @@ protected function get_known_failures(): array { 'icu-regextst:3839', ); - // PCRE2 rejects a range with a class at one end, like "[\d-z]". PCRE 8 reads the "-" literally. - if ( $is_pcre2 ) { - array_push( - $failures, - 'mysql-server-suite:9539', - 'mysql-server-suite:9540', - 'mysql-server-suite:9541', - 'mysql-server-suite:9542', - 'mysql-server-suite:9543', - 'mysql-server-suite:9544', - 'mysql-server-suite:9545', - 'mysql-server-suite:9546', - 'mysql-server-suite:9547', - 'mysql-server-suite:9548', - 'mysql-server-suite:9549', - 'mysql-server-suite:9550', - 'mysql-server-suite:9551', - 'mysql-server-suite:9552', - 'mysql-server-suite:9553', - 'mysql-server-suite:9554', - 'mysql-server-suite:9555', - 'mysql-server-suite:9556', - 'mysql-server-suite:9557', - 'mysql-server-suite:9558', - 'mysql-server-suite:9559', - 'mysql-server-suite:9560', - 'mysql-server-suite:9561', - 'mysql-server-suite:9562', - 'mysql-server-suite:9563', - 'mysql-server-suite:9564', - 'mysql-server-suite:9565', - 'mysql-server-suite:9566', - 'mysql-server-suite:9567', - 'mysql-server-suite:9568', - 'mysql-server-suite:9569', - 'mysql-server-suite:9570', - 'mysql-server-suite:9571', - 'mysql-server-suite:9572', - 'mysql-server-suite:9573', - 'mysql-server-suite:9574', - 'mysql-server-suite:9575', - 'mysql-server-suite:9576', - 'mysql-server-suite:9577', - 'mysql-server-suite:9578', - 'mysql-server-suite:9579', - 'mysql-server-suite:9580', - 'mysql-server-suite:9581', - 'mysql-server-suite:9582', - 'mysql-server-suite:9583', - 'mysql-server-suite:9584', - 'mysql-server-suite:9585', - 'mysql-server-suite:9586', - 'mysql-server-suite:9587', - 'mysql-server-suite:9588', - 'mysql-server-suite:9589', - 'mysql-server-suite:9590', - 'mysql-server-suite:9617', - 'mysql-server-suite:9618', - 'mysql-server-suite:9619', - 'mysql-server-suite:9620', - 'mysql-server-suite:9621', - 'mysql-server-suite:9622', - 'mysql-server-suite:9623', - 'mysql-server-suite:9624', - 'mysql-server-suite:9625', - 'mysql-server-suite:9626', - 'mysql-server-suite:9627', - 'mysql-server-suite:9628', - 'mysql-server-suite:9629', - 'mysql-server-suite:9630', - 'mysql-server-suite:9631', - 'mysql-server-suite:9632', - 'mysql-server-suite:9633', - 'mysql-server-suite:9634', - 'mysql-server-suite:9635', - 'mysql-server-suite:9636', - 'mysql-server-suite:9637', - 'mysql-server-suite:9638', - 'mysql-server-suite:9639', - 'mysql-server-suite:9640', - 'mysql-server-suite:9641', - 'mysql-server-suite:9642', - 'mysql-server-suite:9645', - 'mysql-server-suite:9646', - 'mysql-server-suite:9663', - 'mysql-server-suite:9664', - 'icu-regextst:1037', - 'icu-regextst:1038', - 'icu-regextst:2460', - 'icu-regextst:2461', - 'icu-regextst:2462', - 'icu-regextst:2463', - 'icu-regextst:2464', - 'icu-regextst:2465', - 'icu-regextst:2466', - 'icu-regextst:2467', - 'icu-regextst:2468', - 'icu-regextst:2469', - 'icu-regextst:2470', - 'icu-regextst:2471', - 'icu-regextst:3892', - 'icu-regextst:3893', - 'icu-regextst:3894', - 'icu-regextst:3895', - 'icu-regextst:3896', - 'icu-regextst:3897', - 'icu-regextst:3898', - 'icu-regextst:3899', - 'icu-regextst:3900', - 'icu-regextst:3901', - 'icu-regextst:3902', - 'icu-regextst:3903' - ); - } - - // PCRE2 rejects a set difference after a class, like "[\w--b]". PCRE 8 reads the "-" literally, which gives MySQL's results here. - if ( $is_pcre2 ) { - array_push( - $failures, - 'icu-regextst:1033' - ); - } - // PCRE 8 rejects this nested lookbehind as not fixed in length. if ( ! $is_pcre2 ) { array_push( diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index 491683e35..bbb37c4a6 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -16,54 +16,6 @@ protected function get_known_failures(): array { $failures = array( 'mysql-server-suite:7923', 'mysql-server-suite:7924', - 'mysql-server-suite:9591', - 'mysql-server-suite:9592', - 'mysql-server-suite:9593', - 'mysql-server-suite:9594', - 'mysql-server-suite:9595', - 'mysql-server-suite:9596', - 'mysql-server-suite:9597', - 'mysql-server-suite:9598', - 'mysql-server-suite:9599', - 'mysql-server-suite:9600', - 'mysql-server-suite:9601', - 'mysql-server-suite:9602', - 'mysql-server-suite:9603', - 'mysql-server-suite:9604', - 'mysql-server-suite:9605', - 'mysql-server-suite:9606', - 'mysql-server-suite:9607', - 'mysql-server-suite:9608', - 'mysql-server-suite:9609', - 'mysql-server-suite:9610', - 'mysql-server-suite:9611', - 'mysql-server-suite:9612', - 'mysql-server-suite:9613', - 'mysql-server-suite:9614', - 'mysql-server-suite:9615', - 'mysql-server-suite:9616', - 'mysql-server-suite:9643', - 'mysql-server-suite:9644', - 'mysql-server-suite:9647', - 'mysql-server-suite:9648', - 'mysql-server-suite:9649', - 'mysql-server-suite:9650', - 'mysql-server-suite:9651', - 'mysql-server-suite:9652', - 'mysql-server-suite:9653', - 'mysql-server-suite:9654', - 'mysql-server-suite:9655', - 'mysql-server-suite:9656', - 'mysql-server-suite:9657', - 'mysql-server-suite:9658', - 'mysql-server-suite:9659', - 'mysql-server-suite:9660', - 'mysql-server-suite:9661', - 'mysql-server-suite:9662', - 'mysql-server-suite:9665', - 'mysql-server-suite:9666', - 'mysql-server-suite:9667', - 'mysql-server-suite:9668', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -238,20 +190,6 @@ protected function get_known_failures(): array { 'icu-regextst:384', 'icu-regextst:385', 'icu-regextst:386', - 'icu-regextst:387', - 'icu-regextst:388', - 'icu-regextst:389', - 'icu-regextst:390', - 'icu-regextst:391', - 'icu-regextst:392', - 'icu-regextst:393', - 'icu-regextst:394', - 'icu-regextst:395', - 'icu-regextst:396', - 'icu-regextst:397', - 'icu-regextst:398', - 'icu-regextst:399', - 'icu-regextst:400', 'icu-regextst:520', 'icu-regextst:521', 'icu-regextst:522', @@ -276,8 +214,6 @@ protected function get_known_failures(): array { 'icu-regextst:581', 'icu-regextst:582', 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -308,10 +244,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:931', - 'icu-regextst:932', - 'icu-regextst:933', - 'icu-regextst:934', 'icu-regextst:935', 'icu-regextst:936', 'icu-regextst:941', @@ -320,79 +252,20 @@ protected function get_known_failures(): array { 'icu-regextst:950', 'icu-regextst:951', 'icu-regextst:952', - 'icu-regextst:953', - 'icu-regextst:954', 'icu-regextst:963', 'icu-regextst:964', - 'icu-regextst:965', - 'icu-regextst:966', 'icu-regextst:967', 'icu-regextst:968', 'icu-regextst:969', 'icu-regextst:970', - 'icu-regextst:975', - 'icu-regextst:976', - 'icu-regextst:977', - 'icu-regextst:978', 'icu-regextst:979', 'icu-regextst:980', - 'icu-regextst:981', - 'icu-regextst:982', - 'icu-regextst:985', - 'icu-regextst:986', 'icu-regextst:993', 'icu-regextst:994', 'icu-regextst:995', 'icu-regextst:996', - 'icu-regextst:997', - 'icu-regextst:998', - 'icu-regextst:999', - 'icu-regextst:1000', - 'icu-regextst:1001', - 'icu-regextst:1002', - 'icu-regextst:1003', - 'icu-regextst:1004', - 'icu-regextst:1005', - 'icu-regextst:1006', - 'icu-regextst:1007', - 'icu-regextst:1008', - 'icu-regextst:1009', - 'icu-regextst:1010', - 'icu-regextst:1011', - 'icu-regextst:1012', - 'icu-regextst:1013', - 'icu-regextst:1014', - 'icu-regextst:1015', - 'icu-regextst:1016', - 'icu-regextst:1017', - 'icu-regextst:1018', 'icu-regextst:1019', - 'icu-regextst:1020', - 'icu-regextst:1021', - 'icu-regextst:1022', - 'icu-regextst:1023', - 'icu-regextst:1024', - 'icu-regextst:1025', - 'icu-regextst:1026', - 'icu-regextst:1027', - 'icu-regextst:1028', - 'icu-regextst:1031', - 'icu-regextst:1032', - 'icu-regextst:1034', - 'icu-regextst:1035', - 'icu-regextst:1036', - 'icu-regextst:1039', - 'icu-regextst:1040', - 'icu-regextst:1041', - 'icu-regextst:1042', - 'icu-regextst:1043', - 'icu-regextst:1044', - 'icu-regextst:1047', - 'icu-regextst:1048', - 'icu-regextst:1049', - 'icu-regextst:1050', - 'icu-regextst:1051', - 'icu-regextst:1052', + 'icu-regextst:1033', 'icu-regextst:1055', 'icu-regextst:1056', 'icu-regextst:1057', @@ -451,8 +324,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', 'icu-regextst:1135', 'icu-regextst:1136', 'icu-regextst:1137', @@ -467,8 +338,6 @@ protected function get_known_failures(): array { 'icu-regextst:1182', 'icu-regextst:1185', 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -697,129 +566,6 @@ protected function get_known_failures(): array { 'icu-regextst:3839', ); - // PCRE2 rejects a range with a class at one end, like "[\d-z]". PCRE 8 reads the "-" literally. - if ( $is_pcre2 ) { - array_push( - $failures, - 'mysql-server-suite:9539', - 'mysql-server-suite:9540', - 'mysql-server-suite:9541', - 'mysql-server-suite:9542', - 'mysql-server-suite:9543', - 'mysql-server-suite:9544', - 'mysql-server-suite:9545', - 'mysql-server-suite:9546', - 'mysql-server-suite:9547', - 'mysql-server-suite:9548', - 'mysql-server-suite:9549', - 'mysql-server-suite:9550', - 'mysql-server-suite:9551', - 'mysql-server-suite:9552', - 'mysql-server-suite:9553', - 'mysql-server-suite:9554', - 'mysql-server-suite:9555', - 'mysql-server-suite:9556', - 'mysql-server-suite:9557', - 'mysql-server-suite:9558', - 'mysql-server-suite:9559', - 'mysql-server-suite:9560', - 'mysql-server-suite:9561', - 'mysql-server-suite:9562', - 'mysql-server-suite:9563', - 'mysql-server-suite:9564', - 'mysql-server-suite:9565', - 'mysql-server-suite:9566', - 'mysql-server-suite:9567', - 'mysql-server-suite:9568', - 'mysql-server-suite:9569', - 'mysql-server-suite:9570', - 'mysql-server-suite:9571', - 'mysql-server-suite:9572', - 'mysql-server-suite:9573', - 'mysql-server-suite:9574', - 'mysql-server-suite:9575', - 'mysql-server-suite:9576', - 'mysql-server-suite:9577', - 'mysql-server-suite:9578', - 'mysql-server-suite:9579', - 'mysql-server-suite:9580', - 'mysql-server-suite:9581', - 'mysql-server-suite:9582', - 'mysql-server-suite:9583', - 'mysql-server-suite:9584', - 'mysql-server-suite:9585', - 'mysql-server-suite:9586', - 'mysql-server-suite:9587', - 'mysql-server-suite:9588', - 'mysql-server-suite:9589', - 'mysql-server-suite:9590', - 'mysql-server-suite:9617', - 'mysql-server-suite:9618', - 'mysql-server-suite:9619', - 'mysql-server-suite:9620', - 'mysql-server-suite:9621', - 'mysql-server-suite:9622', - 'mysql-server-suite:9623', - 'mysql-server-suite:9624', - 'mysql-server-suite:9625', - 'mysql-server-suite:9626', - 'mysql-server-suite:9627', - 'mysql-server-suite:9628', - 'mysql-server-suite:9629', - 'mysql-server-suite:9630', - 'mysql-server-suite:9631', - 'mysql-server-suite:9632', - 'mysql-server-suite:9633', - 'mysql-server-suite:9634', - 'mysql-server-suite:9635', - 'mysql-server-suite:9636', - 'mysql-server-suite:9637', - 'mysql-server-suite:9638', - 'mysql-server-suite:9639', - 'mysql-server-suite:9640', - 'mysql-server-suite:9641', - 'mysql-server-suite:9642', - 'mysql-server-suite:9645', - 'mysql-server-suite:9646', - 'mysql-server-suite:9663', - 'mysql-server-suite:9664', - 'icu-regextst:1037', - 'icu-regextst:1038', - 'icu-regextst:2460', - 'icu-regextst:2461', - 'icu-regextst:2462', - 'icu-regextst:2463', - 'icu-regextst:2464', - 'icu-regextst:2465', - 'icu-regextst:2466', - 'icu-regextst:2467', - 'icu-regextst:2468', - 'icu-regextst:2469', - 'icu-regextst:2470', - 'icu-regextst:2471', - 'icu-regextst:3892', - 'icu-regextst:3893', - 'icu-regextst:3894', - 'icu-regextst:3895', - 'icu-regextst:3896', - 'icu-regextst:3897', - 'icu-regextst:3898', - 'icu-regextst:3899', - 'icu-regextst:3900', - 'icu-regextst:3901', - 'icu-regextst:3902', - 'icu-regextst:3903' - ); - } - - // PCRE2 rejects a set difference after a class, like "[\w--b]". PCRE 8 reads the "-" literally, which gives MySQL's results here. - if ( $is_pcre2 ) { - array_push( - $failures, - 'icu-regextst:1033' - ); - } - // PCRE 8 rejects this nested lookbehind as not fixed in length. if ( ! $is_pcre2 ) { array_push( From cfbb638d1959a0a1c7aaa042b78d213a98a19e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 17:04:01 +0100 Subject: [PATCH 5/9] Translate ICU's code point escapes ICU reads "\uhhhh" and "\Uhhhhhhhh" as code points, which PCRE rejects. It reads "\0ooo" as an octal code point with up to three digits, where PCRE reads up to two, so "\0101" matched "\010" and "1" instead of "A". Translate them to "\x{...}", also in sets. Like in ICU, a surrogate pair of "\u" escapes is one code point. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 43 +++++-- .../tests/WP_MySQL_On_SQLite_Tests.php | 34 +++++- .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 114 ++---------------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 114 ++---------------- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 114 ++---------------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 114 ++---------------- 6 files changed, 99 insertions(+), 434 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index fdaa12654..8b6a1cde2 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -108,6 +108,15 @@ public static function register_for( $pdo ): self { 'regexp_instr' => array( 2, 3, 4, 5, 6 ), ); + /** + * ICU escapes of a code point that PCRE lacks or reads differently: "\uhhhh", + * "\Uhhhhhhhh", "\0ooo" up to "\0377", and "\cX". A surrogate pair of "\u" escapes + * is one code point. ICU's "\cX" keeps the low 5 bits of X, where PCRE flips a bit. + * "\xh" and "\xhh" are here too, as a translation can put a hex digit after them, + * like in "[\x4[5]]". + */ + private const REGEXP_CODE_POINT_ESCAPE = '\\\\u[dD][89abAB][0-9a-fA-F]{2}\\\\u[dD][c-fC-F][0-9a-fA-F]{2}|\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}|\\\\0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)|\\\\x[0-9a-fA-F]{1,2}|\\\\c(?:[\xC0-\xFF][\x80-\xBF]*+|[\s\S])'; + /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ private $regexp_cache = array(); @@ -1310,8 +1319,8 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w /* * PHP 7 can read an unknown escape as literal text. For "\y", that matches ICU, - * but "\u0041" matches "u0041", where ICU matches "A". The "X" modifier makes - * all of them errors, like in PHP 8. + * but ICU rejects "\u004", which has too few digits. The "X" modifier makes all + * of them errors, like in PHP 8. */ $modifiers = $binary_mode ? 'X' : 'uX'; if ( ! $case_sensitive ) { @@ -1421,15 +1430,13 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $without * set otherwise. ICU reads a POSIX class outside of a set, as in "[:alpha:]", as * a set. The set's loops and its leading "^" and "]" are possessive, so that a * long set doesn't exhaust PCRE's stack, and the "]" of "[]" or "[^]" can't end - * the set. + * the set. In a set, a control escape, like "\c]", takes the next character. * * A property name stops at a backslash, so that a long run of "\p{" doesn't - * scan the rest of the pattern each time. A control escape, like "\c[", takes - * the next character, unless it is the delimiter or a NUL byte, which need - * escaping. + * scan the rest of the pattern each time. */ $translated = preg_replace_callback( - '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?[^:]*:\]|(\[\^?+\]?+(?:\\\\Q.*?(?:\\\\E|\z)|\\\\c[^\/\0]|\\\\.|\[:\^?[^:]*:\]|(?1)|[^\\\\\[\]])*+\])|\\\\[pP]\{[^}\\\\]*\}|\\\\c[^\/\0]|\\\\.|[\/\0]/s', + '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?[^:]*:\]|(\[\^?+\]?+(?:\\\\Q.*?(?:\\\\E|\z)|\\\\c.|\\\\.|\[:\^?[^:]*:\]|(?1)|[^\\\\\[\]])*+\])|' . self::REGEXP_CODE_POINT_ESCAPE . '|\\\\[pP]\{[^}\\\\]*\}|\\\\.|[\/\0]/s', function ( $parts ) use ( $pattern, $tokens ) { $token = $parts[0]; if ( isset( $parts[1] ) ) { @@ -1473,7 +1480,7 @@ private function regexp_translate_set( $set, $pattern, $tokens ) { // An escape with its argument is one token, and so is a character, also when the // set isn't valid UTF-8. preg_match_all( - '/\\\\Q.*?(?:\\\\E|\z)|\\\\(?:[pP](?:\{[^}\\\\]*\}|\w)|x(?:\{[^}\\\\]*\}|[0-9a-fA-F]{1,2})|N\{[^}\\\\]*\}|c[^\/\0]|.)|\[:\^?[^:]*:\]|\[\^?|&&|--|[\xC0-\xFF][\x80-\xBF]*|./s', + '/\\\\Q.*?(?:\\\\E|\z)|' . self::REGEXP_CODE_POINT_ESCAPE . '|\\\\(?:[pP](?:\{[^}\\\\]*\}|\w)|[xN]\{[^}\\\\]*\}|.)|\[:\^?[^:]*:\]|\[\^?|&&|--|[\xC0-\xFF][\x80-\xBF]*|./s', $set, $parts ); @@ -1671,7 +1678,25 @@ private function regexp_translate_token( $token, $tokens ) { ); return '\\E' === substr( $token, -2 ) ? $quoted : $quoted . '\\E'; } - return $tokens[ $token ] ?? $token; + if ( isset( $tokens[ $token ] ) ) { + return $tokens[ $token ]; + } + if ( ! preg_match( '/^(?:' . self::REGEXP_CODE_POINT_ESCAPE . ')$/', $token ) ) { + return $token; + } + if ( 'c' === $token[1] ) { + // ICU keeps the low 5 bits of X, and UTF-8 keeps the low 6 bits of a code point + // in its last byte. + $code = ord( substr( $token, -1 ) ) & 0x1F; + } elseif ( '0' === $token[1] ) { + $code = octdec( substr( $token, 2 ) ); + } elseif ( 12 === strlen( $token ) ) { + // A surrogate pair of "\u" escapes. + $code = 0x10000 + ( ( hexdec( substr( $token, 2, 4 ) ) - 0xD800 ) << 10 ) + hexdec( substr( $token, 8, 4 ) ) - 0xDC00; + } else { + $code = hexdec( substr( $token, 2 ) ); + } + return sprintf( '\\x{%X}', $code ); } /** diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 931ec4b3b..565bb8f2a 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -382,7 +382,7 @@ public static function regexpLikeErrors() { return array( 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'Invalid regular expression: (abc.' ), 'unknown escape' => array( "REGEXP_LIKE('y', '\\\\y')", 'Invalid regular expression: \\y.' ), - 'ICU escape' => array( "REGEXP_LIKE('A', '\\\\u0041')", 'Invalid regular expression: \\u0041.' ), + 'short escape' => array( "REGEXP_LIKE('u004', '\\\\u004')", 'Invalid regular expression: \\u004.' ), 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'Invalid regular expression: \\p{Foo}.' ), 'operator escape' => array( "'y' REGEXP '\\\\y'", 'Invalid regular expression: \\y.' ), 'binary escape' => array( "X'FF' REGEXP '\\\\y'", 'Invalid regular expression: \\y.' ), @@ -1584,6 +1584,7 @@ public function testRegexpBigIntegerColumn() { /** * @dataProvider regexpSetCases + * @dataProvider regexpCodePointEscapeCases */ public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { $this->assertQuery( @@ -1688,6 +1689,37 @@ public static function regexpSetCases() { ); } + public static function regexpCodePointEscapeCases() { + return array( + '"\\u"' => array( '\\u0041', 'ABA', 'B' ), + '"\\u" in a set' => array( '[\\u0041c]+', 'AcAcdef', 'def' ), + '"\\u" range' => array( '[\\u0041-\\u0043]', 'ABCD', 'D' ), + '"\\u", 2 bytes' => array( 'caf\\u00e9', 'café', '' ), + '"\\U"' => array( '\\U00010400', '𐐀', '<𐐀>' ), + '"\\U" range' => array( '[\\u0000-\\U0010ffff]+', 'a😀', '' ), + 'negated "\\U" range' => array( '[^\\u0000-\\U0010ffff]', 'a😀', 'a😀' ), + 'surrogate pair' => array( '\\ud800\\udc00', 'a𐀀', 'a<𐀀>' ), + 'surrogate pair, uppercase' => array( '\\uD800\\uDC00', 'a𐀀', 'a<𐀀>' ), + 'escaped backslash' => array( '\\\\\\u0041', 'A', 'A' ), + 'quoted' => array( '\\Q\\u0041\\E', 'u0041', 'u0041' ), + 'octal' => array( '\\0101', 'ABA', 'B' ), + 'octal, 1 and 2 digits' => array( '\\0154\\01442', 'ld2', '' ), + 'octal up to 0377' => array( '\\0376', 'þ', '<þ>' ), + 'octal past 0377' => array( '\\0400', ' 0', '< 0>' ), + 'octal NUL' => array( '\\00', 'a', 'a' ), + 'octal range' => array( '[\\0101-\\0103]', 'ABCD', 'D' ), + '"\\x4" in a nested set' => array( '[\\x4[5]]', "\x045E", "<\x04><5>E" ), + '"\\x4" before quotes' => array( '\\x4\\Q\\E5', "\x045E", "<\x045>E" ), + '"\\x4", quotes in a set' => array( '[\\x4\\Q\\E5]', "\x045E", "<\x04><5>E" ), + '"\\c" and a digit' => array( '\\c1', "q\x11", "q<\x11>" ), + '"\\c?"' => array( '\\c?', "\x7F\x1F", "\x7F<\x1F>" ), + '"\\c/"' => array( '\\c/', "/\x0F", "/<\x0F>" ), + '"\\c\\" at the end' => array( 'a\\c\\', "a\x1C", "" ), + '"\\c" and 2 bytes' => array( "\\c\u{E9}", "\x03\x09", "\x03<\x09>" ), + '"\\c" in a set' => array( '[\\c1]', "q\x11", "q<\x11>" ), + ); + } + /** * @dataProvider regexpInvalidSetCases */ diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index 5f91e237f..a39aae2bc 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -174,18 +174,10 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:329', - 'icu-regextst:330', 'icu-regextst:365', 'icu-regextst:366', 'icu-regextst:367', 'icu-regextst:368', - 'icu-regextst:373', - 'icu-regextst:374', - 'icu-regextst:375', - 'icu-regextst:376', - 'icu-regextst:377', - 'icu-regextst:378', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -210,10 +202,6 @@ protected function get_known_failures(): array { 'icu-regextst:565', 'icu-regextst:566', 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -224,18 +212,10 @@ protected function get_known_failures(): array { 'icu-regextst:631', 'icu-regextst:632', 'icu-regextst:633', - 'icu-regextst:705', - 'icu-regextst:706', - 'icu-regextst:709', - 'icu-regextst:710', 'icu-regextst:711', 'icu-regextst:712', 'icu-regextst:713', 'icu-regextst:714', - 'icu-regextst:715', - 'icu-regextst:716', - 'icu-regextst:717', - 'icu-regextst:718', 'icu-regextst:719', 'icu-regextst:720', 'icu-regextst:725', @@ -244,8 +224,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:935', - 'icu-regextst:936', 'icu-regextst:941', 'icu-regextst:942', 'icu-regextst:949', @@ -352,8 +330,6 @@ protected function get_known_failures(): array { 'icu-regextst:1242', 'icu-regextst:1243', 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -376,8 +352,6 @@ protected function get_known_failures(): array { 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', - 'icu-regextst:1318', - 'icu-regextst:1319', 'icu-regextst:1330', 'icu-regextst:1331', 'icu-regextst:1332', @@ -388,10 +362,6 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1364', - 'icu-regextst:1365', - 'icu-regextst:1366', - 'icu-regextst:1367', 'icu-regextst:1370', 'icu-regextst:1371', 'icu-regextst:1372', @@ -480,90 +450,14 @@ protected function get_known_failures(): array { 'icu-regextst:1457', 'icu-regextst:1458', 'icu-regextst:1459', - 'icu-regextst:1466', - 'icu-regextst:1467', - 'icu-regextst:1468', - 'icu-regextst:1469', - 'icu-regextst:1470', - 'icu-regextst:1471', - 'icu-regextst:1472', - 'icu-regextst:1473', - 'icu-regextst:1474', - 'icu-regextst:1475', - 'icu-regextst:1476', - 'icu-regextst:1477', - 'icu-regextst:1478', - 'icu-regextst:1479', - 'icu-regextst:1480', - 'icu-regextst:1481', - 'icu-regextst:1482', - 'icu-regextst:1483', - 'icu-regextst:1484', - 'icu-regextst:1485', - 'icu-regextst:1490', - 'icu-regextst:1491', 'icu-regextst:1494', 'icu-regextst:1495', 'icu-regextst:1506', 'icu-regextst:1507', 'icu-regextst:1508', 'icu-regextst:1509', - 'icu-regextst:2768', - 'icu-regextst:2769', - 'icu-regextst:2770', - 'icu-regextst:2771', - 'icu-regextst:2772', - 'icu-regextst:2773', - 'icu-regextst:2774', - 'icu-regextst:2775', - 'icu-regextst:2776', - 'icu-regextst:2777', - 'icu-regextst:2778', - 'icu-regextst:2779', - 'icu-regextst:3338', - 'icu-regextst:3339', - 'icu-regextst:3340', - 'icu-regextst:3341', - 'icu-regextst:3342', - 'icu-regextst:3343', - 'icu-regextst:3344', - 'icu-regextst:3345', - 'icu-regextst:3396', - 'icu-regextst:3397', - 'icu-regextst:3398', - 'icu-regextst:3399', - 'icu-regextst:3400', - 'icu-regextst:3401', - 'icu-regextst:3402', - 'icu-regextst:3403', 'icu-regextst:3508', 'icu-regextst:3509', - 'icu-regextst:3518', - 'icu-regextst:3519', - 'icu-regextst:3520', - 'icu-regextst:3521', - 'icu-regextst:3522', - 'icu-regextst:3523', - 'icu-regextst:3524', - 'icu-regextst:3525', - 'icu-regextst:3538', - 'icu-regextst:3539', - 'icu-regextst:3540', - 'icu-regextst:3541', - 'icu-regextst:3542', - 'icu-regextst:3543', - 'icu-regextst:3544', - 'icu-regextst:3545', - 'icu-regextst:3606', - 'icu-regextst:3607', - 'icu-regextst:3608', - 'icu-regextst:3609', - 'icu-regextst:3610', - 'icu-regextst:3611', - 'icu-regextst:3836', - 'icu-regextst:3837', - 'icu-regextst:3838', - 'icu-regextst:3839', ); // PCRE 8 rejects this nested lookbehind as not fixed in length. @@ -708,6 +602,14 @@ protected function get_known_failures(): array { 'icu-regextst:1294', 'icu-regextst:1295', 'icu-regextst:1296', + 'icu-regextst:1470', + 'icu-regextst:1471', + 'icu-regextst:1472', + 'icu-regextst:1473', + 'icu-regextst:1478', + 'icu-regextst:1479', + 'icu-regextst:1480', + 'icu-regextst:1481', 'icu-regextst:1504', 'icu-regextst:1505' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index 1a57541b3..ad5f2002a 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -172,18 +172,10 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:329', - 'icu-regextst:330', 'icu-regextst:365', 'icu-regextst:366', 'icu-regextst:367', 'icu-regextst:368', - 'icu-regextst:373', - 'icu-regextst:374', - 'icu-regextst:375', - 'icu-regextst:376', - 'icu-regextst:377', - 'icu-regextst:378', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -208,10 +200,6 @@ protected function get_known_failures(): array { 'icu-regextst:565', 'icu-regextst:566', 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -222,18 +210,10 @@ protected function get_known_failures(): array { 'icu-regextst:631', 'icu-regextst:632', 'icu-regextst:633', - 'icu-regextst:705', - 'icu-regextst:706', - 'icu-regextst:709', - 'icu-regextst:710', 'icu-regextst:711', 'icu-regextst:712', 'icu-regextst:713', 'icu-regextst:714', - 'icu-regextst:715', - 'icu-regextst:716', - 'icu-regextst:717', - 'icu-regextst:718', 'icu-regextst:719', 'icu-regextst:720', 'icu-regextst:725', @@ -242,8 +222,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:935', - 'icu-regextst:936', 'icu-regextst:941', 'icu-regextst:942', 'icu-regextst:949', @@ -346,8 +324,6 @@ protected function get_known_failures(): array { 'icu-regextst:1240', 'icu-regextst:1241', 'icu-regextst:1242', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -362,8 +338,6 @@ protected function get_known_failures(): array { 'icu-regextst:1264', 'icu-regextst:1301', 'icu-regextst:1302', - 'icu-regextst:1318', - 'icu-regextst:1319', 'icu-regextst:1330', 'icu-regextst:1331', 'icu-regextst:1332', @@ -374,10 +348,6 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1364', - 'icu-regextst:1365', - 'icu-regextst:1366', - 'icu-regextst:1367', 'icu-regextst:1370', 'icu-regextst:1371', 'icu-regextst:1372', @@ -466,88 +436,12 @@ protected function get_known_failures(): array { 'icu-regextst:1457', 'icu-regextst:1458', 'icu-regextst:1459', - 'icu-regextst:1466', - 'icu-regextst:1467', - 'icu-regextst:1468', - 'icu-regextst:1469', - 'icu-regextst:1470', - 'icu-regextst:1471', - 'icu-regextst:1472', - 'icu-regextst:1473', - 'icu-regextst:1474', - 'icu-regextst:1475', - 'icu-regextst:1476', - 'icu-regextst:1477', - 'icu-regextst:1478', - 'icu-regextst:1479', - 'icu-regextst:1480', - 'icu-regextst:1481', - 'icu-regextst:1482', - 'icu-regextst:1483', - 'icu-regextst:1484', - 'icu-regextst:1485', - 'icu-regextst:1490', - 'icu-regextst:1491', 'icu-regextst:1494', 'icu-regextst:1495', 'icu-regextst:1506', 'icu-regextst:1507', 'icu-regextst:1508', 'icu-regextst:1509', - 'icu-regextst:2768', - 'icu-regextst:2769', - 'icu-regextst:2770', - 'icu-regextst:2771', - 'icu-regextst:2772', - 'icu-regextst:2773', - 'icu-regextst:2774', - 'icu-regextst:2775', - 'icu-regextst:2776', - 'icu-regextst:2777', - 'icu-regextst:2778', - 'icu-regextst:2779', - 'icu-regextst:3338', - 'icu-regextst:3339', - 'icu-regextst:3340', - 'icu-regextst:3341', - 'icu-regextst:3342', - 'icu-regextst:3343', - 'icu-regextst:3344', - 'icu-regextst:3345', - 'icu-regextst:3396', - 'icu-regextst:3397', - 'icu-regextst:3398', - 'icu-regextst:3399', - 'icu-regextst:3400', - 'icu-regextst:3401', - 'icu-regextst:3402', - 'icu-regextst:3403', - 'icu-regextst:3518', - 'icu-regextst:3519', - 'icu-regextst:3520', - 'icu-regextst:3521', - 'icu-regextst:3522', - 'icu-regextst:3523', - 'icu-regextst:3524', - 'icu-regextst:3525', - 'icu-regextst:3538', - 'icu-regextst:3539', - 'icu-regextst:3540', - 'icu-regextst:3541', - 'icu-regextst:3542', - 'icu-regextst:3543', - 'icu-regextst:3544', - 'icu-regextst:3545', - 'icu-regextst:3606', - 'icu-regextst:3607', - 'icu-regextst:3608', - 'icu-regextst:3609', - 'icu-regextst:3610', - 'icu-regextst:3611', - 'icu-regextst:3836', - 'icu-regextst:3837', - 'icu-regextst:3838', - 'icu-regextst:3839', ); // PCRE 8 rejects this nested lookbehind as not fixed in length. @@ -683,6 +577,14 @@ protected function get_known_failures(): array { 'icu-regextst:1294', 'icu-regextst:1295', 'icu-regextst:1296', + 'icu-regextst:1470', + 'icu-regextst:1471', + 'icu-regextst:1472', + 'icu-regextst:1473', + 'icu-regextst:1478', + 'icu-regextst:1479', + 'icu-regextst:1480', + 'icu-regextst:1481', 'icu-regextst:1504', 'icu-regextst:1505' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index ac5b96ebf..e3789888f 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -188,18 +188,10 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:329', - 'icu-regextst:330', 'icu-regextst:365', 'icu-regextst:366', 'icu-regextst:367', 'icu-regextst:368', - 'icu-regextst:373', - 'icu-regextst:374', - 'icu-regextst:375', - 'icu-regextst:376', - 'icu-regextst:377', - 'icu-regextst:378', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -224,10 +216,6 @@ protected function get_known_failures(): array { 'icu-regextst:565', 'icu-regextst:566', 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -238,18 +226,10 @@ protected function get_known_failures(): array { 'icu-regextst:631', 'icu-regextst:632', 'icu-regextst:633', - 'icu-regextst:705', - 'icu-regextst:706', - 'icu-regextst:709', - 'icu-regextst:710', 'icu-regextst:711', 'icu-regextst:712', 'icu-regextst:713', 'icu-regextst:714', - 'icu-regextst:715', - 'icu-regextst:716', - 'icu-regextst:717', - 'icu-regextst:718', 'icu-regextst:719', 'icu-regextst:720', 'icu-regextst:725', @@ -265,8 +245,6 @@ protected function get_known_failures(): array { 'icu-regextst:895', 'icu-regextst:896', 'icu-regextst:919', - 'icu-regextst:935', - 'icu-regextst:936', 'icu-regextst:941', 'icu-regextst:942', 'icu-regextst:949', @@ -375,8 +353,6 @@ protected function get_known_failures(): array { 'icu-regextst:1242', 'icu-regextst:1243', 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -399,8 +375,6 @@ protected function get_known_failures(): array { 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', - 'icu-regextst:1318', - 'icu-regextst:1319', 'icu-regextst:1330', 'icu-regextst:1331', 'icu-regextst:1332', @@ -411,10 +385,6 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1364', - 'icu-regextst:1365', - 'icu-regextst:1366', - 'icu-regextst:1367', 'icu-regextst:1370', 'icu-regextst:1371', 'icu-regextst:1372', @@ -503,28 +473,6 @@ protected function get_known_failures(): array { 'icu-regextst:1457', 'icu-regextst:1458', 'icu-regextst:1459', - 'icu-regextst:1466', - 'icu-regextst:1467', - 'icu-regextst:1468', - 'icu-regextst:1469', - 'icu-regextst:1470', - 'icu-regextst:1471', - 'icu-regextst:1472', - 'icu-regextst:1473', - 'icu-regextst:1474', - 'icu-regextst:1475', - 'icu-regextst:1476', - 'icu-regextst:1477', - 'icu-regextst:1478', - 'icu-regextst:1479', - 'icu-regextst:1480', - 'icu-regextst:1481', - 'icu-regextst:1482', - 'icu-regextst:1483', - 'icu-regextst:1484', - 'icu-regextst:1485', - 'icu-regextst:1490', - 'icu-regextst:1491', 'icu-regextst:1494', 'icu-regextst:1495', 'icu-regextst:1506', @@ -533,62 +481,8 @@ protected function get_known_failures(): array { 'icu-regextst:1509', 'icu-regextst:1872', 'icu-regextst:1873', - 'icu-regextst:2768', - 'icu-regextst:2769', - 'icu-regextst:2770', - 'icu-regextst:2771', - 'icu-regextst:2772', - 'icu-regextst:2773', - 'icu-regextst:2774', - 'icu-regextst:2775', - 'icu-regextst:2776', - 'icu-regextst:2777', - 'icu-regextst:2778', - 'icu-regextst:2779', - 'icu-regextst:3338', - 'icu-regextst:3339', - 'icu-regextst:3340', - 'icu-regextst:3341', - 'icu-regextst:3342', - 'icu-regextst:3343', - 'icu-regextst:3344', - 'icu-regextst:3345', - 'icu-regextst:3396', - 'icu-regextst:3397', - 'icu-regextst:3398', - 'icu-regextst:3399', - 'icu-regextst:3400', - 'icu-regextst:3401', - 'icu-regextst:3402', - 'icu-regextst:3403', 'icu-regextst:3508', 'icu-regextst:3509', - 'icu-regextst:3518', - 'icu-regextst:3519', - 'icu-regextst:3520', - 'icu-regextst:3521', - 'icu-regextst:3522', - 'icu-regextst:3523', - 'icu-regextst:3524', - 'icu-regextst:3525', - 'icu-regextst:3538', - 'icu-regextst:3539', - 'icu-regextst:3540', - 'icu-regextst:3541', - 'icu-regextst:3542', - 'icu-regextst:3543', - 'icu-regextst:3544', - 'icu-regextst:3545', - 'icu-regextst:3606', - 'icu-regextst:3607', - 'icu-regextst:3608', - 'icu-regextst:3609', - 'icu-regextst:3610', - 'icu-regextst:3611', - 'icu-regextst:3836', - 'icu-regextst:3837', - 'icu-regextst:3838', - 'icu-regextst:3839', ); // PCRE 8 rejects this nested lookbehind as not fixed in length. @@ -737,6 +631,14 @@ protected function get_known_failures(): array { 'icu-regextst:1294', 'icu-regextst:1295', 'icu-regextst:1296', + 'icu-regextst:1470', + 'icu-regextst:1471', + 'icu-regextst:1472', + 'icu-regextst:1473', + 'icu-regextst:1478', + 'icu-regextst:1479', + 'icu-regextst:1480', + 'icu-regextst:1481', 'icu-regextst:1504', 'icu-regextst:1505' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index bbb37c4a6..ee405ce26 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -174,18 +174,10 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:329', - 'icu-regextst:330', 'icu-regextst:365', 'icu-regextst:366', 'icu-regextst:367', 'icu-regextst:368', - 'icu-regextst:373', - 'icu-regextst:374', - 'icu-regextst:375', - 'icu-regextst:376', - 'icu-regextst:377', - 'icu-regextst:378', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -210,10 +202,6 @@ protected function get_known_failures(): array { 'icu-regextst:565', 'icu-regextst:566', 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', 'icu-regextst:590', 'icu-regextst:591', 'icu-regextst:626', @@ -224,18 +212,10 @@ protected function get_known_failures(): array { 'icu-regextst:631', 'icu-regextst:632', 'icu-regextst:633', - 'icu-regextst:705', - 'icu-regextst:706', - 'icu-regextst:709', - 'icu-regextst:710', 'icu-regextst:711', 'icu-regextst:712', 'icu-regextst:713', 'icu-regextst:714', - 'icu-regextst:715', - 'icu-regextst:716', - 'icu-regextst:717', - 'icu-regextst:718', 'icu-regextst:719', 'icu-regextst:720', 'icu-regextst:725', @@ -244,8 +224,6 @@ protected function get_known_failures(): array { 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:935', - 'icu-regextst:936', 'icu-regextst:941', 'icu-regextst:942', 'icu-regextst:949', @@ -352,8 +330,6 @@ protected function get_known_failures(): array { 'icu-regextst:1242', 'icu-regextst:1243', 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -376,8 +352,6 @@ protected function get_known_failures(): array { 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', - 'icu-regextst:1318', - 'icu-regextst:1319', 'icu-regextst:1330', 'icu-regextst:1331', 'icu-regextst:1332', @@ -388,10 +362,6 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1364', - 'icu-regextst:1365', - 'icu-regextst:1366', - 'icu-regextst:1367', 'icu-regextst:1370', 'icu-regextst:1371', 'icu-regextst:1372', @@ -480,90 +450,14 @@ protected function get_known_failures(): array { 'icu-regextst:1457', 'icu-regextst:1458', 'icu-regextst:1459', - 'icu-regextst:1466', - 'icu-regextst:1467', - 'icu-regextst:1468', - 'icu-regextst:1469', - 'icu-regextst:1470', - 'icu-regextst:1471', - 'icu-regextst:1472', - 'icu-regextst:1473', - 'icu-regextst:1474', - 'icu-regextst:1475', - 'icu-regextst:1476', - 'icu-regextst:1477', - 'icu-regextst:1478', - 'icu-regextst:1479', - 'icu-regextst:1480', - 'icu-regextst:1481', - 'icu-regextst:1482', - 'icu-regextst:1483', - 'icu-regextst:1484', - 'icu-regextst:1485', - 'icu-regextst:1490', - 'icu-regextst:1491', 'icu-regextst:1494', 'icu-regextst:1495', 'icu-regextst:1506', 'icu-regextst:1507', 'icu-regextst:1508', 'icu-regextst:1509', - 'icu-regextst:2768', - 'icu-regextst:2769', - 'icu-regextst:2770', - 'icu-regextst:2771', - 'icu-regextst:2772', - 'icu-regextst:2773', - 'icu-regextst:2774', - 'icu-regextst:2775', - 'icu-regextst:2776', - 'icu-regextst:2777', - 'icu-regextst:2778', - 'icu-regextst:2779', - 'icu-regextst:3338', - 'icu-regextst:3339', - 'icu-regextst:3340', - 'icu-regextst:3341', - 'icu-regextst:3342', - 'icu-regextst:3343', - 'icu-regextst:3344', - 'icu-regextst:3345', - 'icu-regextst:3396', - 'icu-regextst:3397', - 'icu-regextst:3398', - 'icu-regextst:3399', - 'icu-regextst:3400', - 'icu-regextst:3401', - 'icu-regextst:3402', - 'icu-regextst:3403', 'icu-regextst:3508', 'icu-regextst:3509', - 'icu-regextst:3518', - 'icu-regextst:3519', - 'icu-regextst:3520', - 'icu-regextst:3521', - 'icu-regextst:3522', - 'icu-regextst:3523', - 'icu-regextst:3524', - 'icu-regextst:3525', - 'icu-regextst:3538', - 'icu-regextst:3539', - 'icu-regextst:3540', - 'icu-regextst:3541', - 'icu-regextst:3542', - 'icu-regextst:3543', - 'icu-regextst:3544', - 'icu-regextst:3545', - 'icu-regextst:3606', - 'icu-regextst:3607', - 'icu-regextst:3608', - 'icu-regextst:3609', - 'icu-regextst:3610', - 'icu-regextst:3611', - 'icu-regextst:3836', - 'icu-regextst:3837', - 'icu-regextst:3838', - 'icu-regextst:3839', ); // PCRE 8 rejects this nested lookbehind as not fixed in length. @@ -708,6 +602,14 @@ protected function get_known_failures(): array { 'icu-regextst:1294', 'icu-regextst:1295', 'icu-regextst:1296', + 'icu-regextst:1470', + 'icu-regextst:1471', + 'icu-regextst:1472', + 'icu-regextst:1473', + 'icu-regextst:1478', + 'icu-regextst:1479', + 'icu-regextst:1480', + 'icu-regextst:1481', 'icu-regextst:1504', 'icu-regextst:1505' ); From d0349441fb70dd28b53ac0fc8ccdfa92f2d15dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 17:05:59 +0100 Subject: [PATCH 6/9] Read escaped letters literally where ICU does ICU reads an escaped letter that it gives no meaning, like "\y", as the letter. PCRE rejects most of these, and gives others a meaning: "\C" matches one byte of a character, and "[\b]" matches a backspace. Translate these escapes to their letters, which replaces the special case for "\K". The lists of letters, outside of a set and in a set, come from MySQL 8.4. In a set, "\G" is now a letter too. Before, it failed to compile in a search that didn't start where the previous match ended. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 38 ++++++++++++------- .../tests/WP_MySQL_On_SQLite_Tests.php | 37 ++++++++++++++++-- .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 14 ------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 14 ------- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 14 ------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 14 ------- 6 files changed, 58 insertions(+), 73 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 8b6a1cde2..3fb03dae1 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -117,6 +117,18 @@ public static function register_for( $pdo ): self { */ private const REGEXP_CODE_POINT_ESCAPE = '\\\\u[dD][89abAB][0-9a-fA-F]{2}\\\\u[dD][c-fC-F][0-9a-fA-F]{2}|\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}|\\\\0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)|\\\\x[0-9a-fA-F]{1,2}|\\\\c(?:[\xC0-\xFF][\x80-\xBF]*+|[\s\S])'; + /** + * Letters that ICU reads literally after a backslash, outside of a set. PCRE rejects + * most of them, and reads some differently, like "\K". + */ + private const REGEXP_LITERAL_ESCAPES = 'gijlmoqyCEFIJKLMOTY'; + + /** + * Letters that ICU reads literally after a backslash, in a set. PCRE rejects most of + * them, and reads some differently, like "\b". + */ + private const REGEXP_LITERAL_SET_ESCAPES = 'bgijklmoqyzABCEFGIJKLMORTXYZ'; + /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ private $regexp_cache = array(); @@ -1247,9 +1259,9 @@ private function regexp_check_match_type( $function_name, $match_type ) { * (UTF-8) modifier is applied unless byte-oriented matching is requested. * Case-insensitive is the default. * - * MySQL uses ICU, which differs from PCRE in some syntax, like ICU-only escapes. - * The known failures of the REGEXP test suites list these cases. Other known - * differences: + * MySQL uses ICU, which differs from PCRE in some syntax, like `\N{...}` and + * property names. The known failures of the REGEXP test suites list these cases. + * Other known differences: * * - Text matching ignores case unless the `c` flag is passed, as the column * collation isn't known here. @@ -1318,9 +1330,8 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w } /* - * PHP 7 can read an unknown escape as literal text. For "\y", that matches ICU, - * but ICU rejects "\u004", which has too few digits. The "X" modifier makes all - * of them errors, like in PHP 8. + * PHP 7 can read an unknown escape, like "\u004", as literal text. The "X" modifier + * makes it an error, like in ICU and PHP 8. */ $modifiers = $binary_mode ? 'X' : 'uX'; if ( ! $case_sensitive ) { @@ -1392,12 +1403,6 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $without // PCRE's [:punct:] also holds ASCII symbols like "+", where ICU's doesn't. '[:punct:]' => '\\p{P}', '[:^punct:]' => '\\P{P}', - - /* - * ICU reads "\K" as "K". In PCRE, "\K" moves the start of the match, even to - * before the place where the search started, like in "(?<=\Ka)". - */ - '\\K' => 'K', ); if ( $without_g ) { // A position can't be both a word boundary and not one, so "\b\B" never @@ -1516,7 +1521,7 @@ private function regexp_translate_set( $set, $pattern, $tokens ) { private function regexp_parse_set( array $parts, &$position, $pattern, $tokens ) { // An escape is translated, and another character is escaped if PCRE needs it. $literal = function ( $part ) use ( $tokens ) { - return '\\' === $part[0] ? $this->regexp_translate_token( $part, $tokens ) : ( $tokens[ $part ] ?? preg_quote( $part ) ); + return '\\' === $part[0] ? $this->regexp_translate_token( $part, $tokens, true ) : ( $tokens[ $part ] ?? preg_quote( $part ) ); }; $negated = '[^' === $parts[ $position++ ]; @@ -1661,10 +1666,11 @@ private function regexp_set_fragment( array $set ) { * * @param string $token The token. * @param string[] $tokens Translations of tokens. + * @param bool $in_set Whether the token is in a set. * * @return string The PCRE equivalent. */ - private function regexp_translate_token( $token, $tokens ) { + private function regexp_translate_token( $token, $tokens, $in_set = false ) { if ( '\\Q' === substr( $token, 0, 2 ) ) { // Quoting can't hold the delimiter or NUL bytes, so they are escaped between // two quotes. Quoted text that runs to the end gets an "\E", so that a trailing @@ -1678,6 +1684,10 @@ private function regexp_translate_token( $token, $tokens ) { ); return '\\E' === substr( $token, -2 ) ? $quoted : $quoted . '\\E'; } + $letters = $in_set ? self::REGEXP_LITERAL_SET_ESCAPES : self::REGEXP_LITERAL_ESCAPES; + if ( 2 === strlen( $token ) && '\\' === $token[0] && false !== strpos( $letters, $token[1] ) ) { + return $token[1]; + } if ( isset( $tokens[ $token ] ) ) { return $tokens[ $token ]; } diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 565bb8f2a..61ac59b9f 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -381,11 +381,8 @@ public function testRegexpLikeErrors( $sql, $message ) { public static function regexpLikeErrors() { return array( 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'Invalid regular expression: (abc.' ), - 'unknown escape' => array( "REGEXP_LIKE('y', '\\\\y')", 'Invalid regular expression: \\y.' ), 'short escape' => array( "REGEXP_LIKE('u004', '\\\\u004')", 'Invalid regular expression: \\u004.' ), 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'Invalid regular expression: \\p{Foo}.' ), - 'operator escape' => array( "'y' REGEXP '\\\\y'", 'Invalid regular expression: \\y.' ), - 'binary escape' => array( "X'FF' REGEXP '\\\\y'", 'Invalid regular expression: \\y.' ), 'extra argument' => array( "REGEXP_LIKE('abc', 'abc', 'c', 'extra')", 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_LIKE()', @@ -393,6 +390,20 @@ public static function regexpLikeErrors() { ); } + public function testRegexpOperatorLiteralEscape() { + // The REGEXP operator reads "\y" literally too, also when it matches bytes. + $this->assertQuery( "SELECT 'y' REGEXP '\\\\y' AS text_result, X'FF79' REGEXP '\\\\y' AS binary_result" ); + $this->assertEquals( + array( + (object) array( + 'text_result' => '1', + 'binary_result' => '1', + ), + ), + $this->last_result + ); + } + /** * @dataProvider regexpMatchTypeFlagCases */ @@ -1184,6 +1195,7 @@ public static function regexpMatchEndAnchorCases() { 'REGEXP_REPLACE, second occurrence' => array( "REGEXP_REPLACE('aab', '\\\\Ga', '-', 1, 2)", 'a-b' ), 'REGEXP_REPLACE, in a comment' => array( "REGEXP_REPLACE('aa', '(?#\\\\G)a', 'x', 2)", 'ax' ), 'REGEXP_REPLACE, escaped backslash' => array( "REGEXP_REPLACE('a\\\\Gb', '\\\\\\\\G', '-', 2)", 'a-b' ), + 'REGEXP_REPLACE, letter in a set' => array( "REGEXP_REPLACE('aGb', '[\\\\G]', 'x', 2)", 'axb' ), 'REGEXP_SUBSTR, after empty match' => array( "REGEXP_SUBSTR('abc', '\\\\G', 1, 2)", null ), 'REGEXP_SUBSTR, pos' => array( "REGEXP_SUBSTR('abc', '\\\\G.', 2)", null ), @@ -1585,6 +1597,7 @@ public function testRegexpBigIntegerColumn() { /** * @dataProvider regexpSetCases * @dataProvider regexpCodePointEscapeCases + * @dataProvider regexpLiteralEscapeCases */ public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { $this->assertQuery( @@ -1720,6 +1733,24 @@ public static function regexpCodePointEscapeCases() { ); } + public static function regexpLiteralEscapeCases() { + return array( + '"\\y"' => array( '\\y', 'xy', 'x' ), + '"\\j" in a set' => array( '[\\j]+', 'jjx', 'x' ), + '"\\K"' => array( 'a\\Kb', 'abaKb', 'ab' ), + '"\\K" in a lookbehind' => array( '(?<=\\Ka)', 'Kaa', 'Ka<>a' ), + '"\\C"' => array( '\\C', 'aC', 'a' ), + '"\\E" outside of quotes' => array( 'a\\Eb', 'abaEb', 'ab' ), + '"\\b" in a set' => array( '[\\b]', 'ab', 'a' ), + '"\\z" in a set' => array( '[\\z]+', 'azz', 'a' ), + '"\\X" in a set' => array( '[\\X]', 'aX', 'a' ), + '"\\b" outside of a set' => array( '\\bb', 'ab b', 'ab ' ), + '"\\z" outside of a set' => array( 'a\\z', 'aa', 'a' ), + '"\\x4\\E"' => array( '\\x4\\E', "\x04E", "<\x04E>" ), + '"\\x4\\b" in a set' => array( '[\\x4\\b]', "\x04bK", "<\x04>K" ), + ); + } + /** * @dataProvider regexpInvalidSetCases */ diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index a39aae2bc..32cf5498b 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -158,8 +158,6 @@ protected function get_known_failures(): array { 'icu-regextst:149', 'icu-regextst:165', 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -174,10 +172,6 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:365', - 'icu-regextst:366', - 'icu-regextst:367', - 'icu-regextst:368', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -218,10 +212,6 @@ protected function get_known_failures(): array { 'icu-regextst:714', 'icu-regextst:719', 'icu-regextst:720', - 'icu-regextst:725', - 'icu-regextst:726', - 'icu-regextst:727', - 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', 'icu-regextst:941', @@ -304,10 +294,6 @@ protected function get_known_failures(): array { 'icu-regextst:1132', 'icu-regextst:1135', 'icu-regextst:1136', - 'icu-regextst:1137', - 'icu-regextst:1138', - 'icu-regextst:1139', - 'icu-regextst:1140', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index ad5f2002a..acf32376c 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -156,8 +156,6 @@ protected function get_known_failures(): array { 'icu-regextst:149', 'icu-regextst:165', 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -172,10 +170,6 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:365', - 'icu-regextst:366', - 'icu-regextst:367', - 'icu-regextst:368', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -216,10 +210,6 @@ protected function get_known_failures(): array { 'icu-regextst:714', 'icu-regextst:719', 'icu-regextst:720', - 'icu-regextst:725', - 'icu-regextst:726', - 'icu-regextst:727', - 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', 'icu-regextst:941', @@ -300,10 +290,6 @@ protected function get_known_failures(): array { 'icu-regextst:1132', 'icu-regextst:1135', 'icu-regextst:1136', - 'icu-regextst:1137', - 'icu-regextst:1138', - 'icu-regextst:1139', - 'icu-regextst:1140', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index e3789888f..99c996406 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -170,8 +170,6 @@ protected function get_known_failures(): array { 'icu-regextst:149', 'icu-regextst:165', 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', 'icu-regextst:217', 'icu-regextst:218', 'icu-regextst:219', @@ -188,10 +186,6 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:365', - 'icu-regextst:366', - 'icu-regextst:367', - 'icu-regextst:368', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -232,10 +226,6 @@ protected function get_known_failures(): array { 'icu-regextst:714', 'icu-regextst:719', 'icu-regextst:720', - 'icu-regextst:725', - 'icu-regextst:726', - 'icu-regextst:727', - 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', 'icu-regextst:879', @@ -325,10 +315,6 @@ protected function get_known_failures(): array { 'icu-regextst:1132', 'icu-regextst:1135', 'icu-regextst:1136', - 'icu-regextst:1137', - 'icu-regextst:1138', - 'icu-regextst:1139', - 'icu-regextst:1140', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1170', diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index ee405ce26..3175a9681 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -158,8 +158,6 @@ protected function get_known_failures(): array { 'icu-regextst:149', 'icu-regextst:165', 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -174,10 +172,6 @@ protected function get_known_failures(): array { 'icu-regextst:232', 'icu-regextst:233', 'icu-regextst:234', - 'icu-regextst:365', - 'icu-regextst:366', - 'icu-regextst:367', - 'icu-regextst:368', 'icu-regextst:383', 'icu-regextst:384', 'icu-regextst:385', @@ -218,10 +212,6 @@ protected function get_known_failures(): array { 'icu-regextst:714', 'icu-regextst:719', 'icu-regextst:720', - 'icu-regextst:725', - 'icu-regextst:726', - 'icu-regextst:727', - 'icu-regextst:728', 'icu-regextst:843', 'icu-regextst:844', 'icu-regextst:941', @@ -304,10 +294,6 @@ protected function get_known_failures(): array { 'icu-regextst:1132', 'icu-regextst:1135', 'icu-regextst:1136', - 'icu-regextst:1137', - 'icu-regextst:1138', - 'icu-regextst:1139', - 'icu-regextst:1140', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', From abe0ec537b98a16ec9c5948aa979ec30d257e4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 17:53:51 +0100 Subject: [PATCH 7/9] Match ICU's word characters in \w and \b MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ICU's word characters are alphabetic ones, all marks, decimal digits, connector punctuation, and the zero-width joiners. PCRE's "\w" misses spacing marks, and before PCRE2 10.43, all marks, so "\w+" split words in Hindi, Thai, or Tamil, and "\b" found boundaries inside them. It also matches other numbers, like "²". Translate "\w", "\W", "\b", and "\B" to ICU's class, which works the same with every PCRE version. Matching bytes keeps PCRE's ASCII class. Like ICU, reject a quantifier after "\b" or "\B", which PCRE would apply to the translated group. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 43 ++++++++++++++++--- .../tests/WP_MySQL_On_SQLite_Tests.php | 27 ++++++++++++ .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 29 ------------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 13 ------ ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 43 ------------------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 29 ------------- 6 files changed, 64 insertions(+), 120 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 3fb03dae1..d5182fa0e 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -129,6 +129,14 @@ public static function register_for( $pdo ): self { */ private const REGEXP_LITERAL_SET_ESCAPES = 'bgijklmoqyzABCEFGIJKLMORTXYZ'; + /** + * ICU's word characters: alphabetic ones, marks, decimal digits, connector punctuation, + * and the zero-width joiners. Alphabetic characters are letters, letter numbers, and + * letters in circles or squares, like "Ⓐ". PCRE's "\w" misses some marks, and it + * matches other numbers, like "²". + */ + private const REGEXP_WORD_CLASS = '\p{L}\p{Nl}\p{M}\p{Nd}\p{Pc}\x{200C}\x{200D}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}'; + /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ private $regexp_cache = array(); @@ -1275,6 +1283,8 @@ private function regexp_check_match_type( $function_name, $match_type ) { * - When ignoring case, ICU applies it to a set after the set's operations, so * `[A-Za-z--aeiou]` matches "a", as "A" stays in the set. Here, the operation * removes both cases. Operands in brackets, like `[a-z--[aeiou]]`, match ICU. + * - ICU attaches a combining mark to the character before it, so a mark after a + * space doesn't start a word for `\b`. Here, it does. * - `\G` in a lookbehind doesn't always match where it does in ICU. * - Data that isn't valid UTF-8 is matched byte by byte and case-sensitively, * like MySQL binary strings. Other binary values match as text, so case @@ -1285,6 +1295,8 @@ private function regexp_check_match_type( $function_name, $match_type ) { * `2.6` means 2 (MySQL: 3), and `'2e1'` means 20 (MySQL: 2). * - A repeated group, like `(a|b)*`, can exceed PCRE's limits on a subject of * about 50,000 characters, or 2,000 on PHP 7.2. + * - `\w` and `\b` become long classes, so a repeated group like + * `(?:\b\w+\b\W*){1,100}` can be too large to compile. * * @param string $pattern The MySQL regex pattern. * @param string $match_type MySQL match_type flag string. @@ -1356,7 +1368,7 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w } else { $newline = '(*ANY)'; } - $compiled = '/' . $newline . $this->regexp_translate_pattern( $pattern, ! $case_sensitive, $without_g ) . '/' . $modifiers; + $compiled = '/' . $newline . $this->regexp_translate_pattern( $pattern, ! $case_sensitive, $binary_mode, $without_g ) . '/' . $modifiers; /* * Compile the pattern by matching it against an empty string. Only a compile @@ -1388,12 +1400,14 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w * * @param string $pattern The regex pattern. * @param bool $case_insensitive Whether the pattern ignores case by default. + * @param bool $binary_mode Whether the pattern matches bytes instead of UTF-8 characters. * @param bool $without_g Whether "\G" never matches. * - * @throws Exception If the pattern can't be split, or it has an invalid set. + * @throws Exception If the pattern can't be split, or it has an invalid set or a + * repeated word boundary. * @return string Pattern safe to wrap in slash delimiters. */ - private function regexp_translate_pattern( $pattern, $case_insensitive, $without_g ) { + private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_mode, $without_g ) { $tokens = array( // The delimiter, and NUL bytes, which PHP before 8.2 rejects in patterns. '/' => '\\/', @@ -1410,6 +1424,17 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $without $tokens['\\G'] = '\\b\\B'; } + // "\w" and "\b" use ICU's word characters, except on bytes. + if ( ! $binary_mode ) { + $word = self::REGEXP_WORD_CLASS; + $tokens += array( + '\\w' => "[$word]", + '\\W' => "[^$word]", + '\\b' => "(?:(?<=[$word])(?![$word])|(? "(?:(?<=[$word])(?=[$word])|(?regexp_translate_token( $token, $tokens ); }, $pattern @@ -1594,7 +1623,9 @@ private function regexp_parse_set( array $parts, &$position, $pattern, $tokens ) $terms[] = array( $tokens[ $part ] ?? $part, true ); $type = 'set'; } elseif ( preg_match( '/^\\\\[dDsSwWhHvV]$/', $part ) ) { - $terms[] = array( $part, true ); + // A translated class, like "[\p{L}...]", joins the set, and a negated one is an alternative. + $class = $tokens[ $part ] ?? $part; + $terms[] = '[^' === substr( $class, 0, 2 ) ? array( $class, false ) : array( trim( $class, '[]' ), true ); $type = 'escape'; } else { $terms[] = array( $literal( $part ), true ); diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 61ac59b9f..d9c1f536d 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -383,6 +383,10 @@ public static function regexpLikeErrors() { 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'Invalid regular expression: (abc.' ), 'short escape' => array( "REGEXP_LIKE('u004', '\\\\u004')", 'Invalid regular expression: \\u004.' ), 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'Invalid regular expression: \\p{Foo}.' ), + '"\\b+"' => array( "REGEXP_LIKE('b', '\\\\b+')", 'Invalid regular expression: \\b+.' ), + '"\\B*"' => array( "REGEXP_LIKE('b', '\\\\B*')", 'Invalid regular expression: \\B*.' ), + '"\\b{2}"' => array( "REGEXP_LIKE('b', '\\\\b{2}')", 'Invalid regular expression: \\b{2}.' ), + '"\\b{x}"' => array( "REGEXP_LIKE('b{x}', '\\\\b{x}')", 'Invalid regular expression: \\b{x}.' ), 'extra argument' => array( "REGEXP_LIKE('abc', 'abc', 'c', 'extra')", 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_LIKE()', @@ -453,6 +457,8 @@ public static function regexpBinaryDataCases() { 'REGEXP_REPLACE, pos one past end' => array( "X'C485FF'", "REGEXP_REPLACE(b, '\$', 'x', 4)", "\xC4\x85\xFFx" ), 'REGEXP_REPLACE, occurrence' => array( "X'C485FF'", "REGEXP_REPLACE(b, '(.)', '[\$1]', 2, 1)", "\xC4[\x85]\xFF" ), 'REGEXP_REPLACE, empty matches' => array( "X'C485FF'", "REGEXP_REPLACE(b, 'x*', '-')", "-\xC4-\x85-\xFF-" ), + 'REGEXP_REPLACE, word characters' => array( "X'61812D62'", "REGEXP_REPLACE(b, '\\\\w', 'x')", "x\x81-x" ), + 'REGEXP_REPLACE, word boundaries' => array( "X'61812D62'", "REGEXP_REPLACE(b, '\\\\b', '|')", "|a|\x81-|b|" ), 'REGEXP_SUBSTR, any byte' => array( "X'61FF62'", "REGEXP_SUBSTR(b, 'a.b')", "a\xFFb" ), 'REGEXP_SUBSTR, other case' => array( "X'61FF41'", "REGEXP_SUBSTR(b, 'a.a')", null ), @@ -1598,6 +1604,7 @@ public function testRegexpBigIntegerColumn() { * @dataProvider regexpSetCases * @dataProvider regexpCodePointEscapeCases * @dataProvider regexpLiteralEscapeCases + * @dataProvider regexpWordCases */ public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { $this->assertQuery( @@ -1751,6 +1758,26 @@ public static function regexpLiteralEscapeCases() { ); } + public static function regexpWordCases() { + return array( + '"\\w" and marks' => array( '\\w+', 'नमस्ते สวัสดี தமிழ்', '<नमस्ते> <สวัสดี> <தமிழ்>' ), + '"\\b" and marks' => array( '\\bहिन्दी\\b', 'हिन्दी है', '<हिन्दी> है' ), + '"\\b" and a combining accent' => array( "\\bcafe\u{301}\\b", "a cafe\u{301} b", "a b" ), + '"\\w" and other numbers' => array( '\\w', 'x²Ⅻ', '²<Ⅻ>' ), + '"\\w" and letter symbols' => array( '\\w', 'Ⓐ🄰', '<Ⓐ><🄰>' ), + '"\\w" and joiners' => array( '\\w+', "ab\u{200C}cd\u{200D}ef", "" ), + '"\\w" and connectors' => array( '\\w', '_‿', '<_><‿>' ), + '"\\W"' => array( '\\W+', "ab\u{200C}cd ²", "ab\u{200C}cd< ²>" ), + '"\\b"' => array( '\\b', 'ab cd', '<>ab<> <>cd<>' ), + '"\\B"' => array( '\\B', 'ab cd', 'a<>b c<>d' ), + '"\\w" in a set' => array( '[\\w]+', 'ab²', '²' ), + '"\\W" in a set' => array( '[\\W]+', 'ab²', 'ab<²>' ), + '"\\W" in a negated set' => array( '[^\\W]+', 'ab² c', '² ' ), + '"\\w" in an intersection' => array( '[\\w&&[^a]]+', 'ab²c', 'a²' ), + '"\\d"' => array( '\\d+', '١٢٣ ²', '<١٢٣> ²' ), + ); + } + /** * @dataProvider regexpInvalidSetCases */ diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index 32cf5498b..e3cd5afb4 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -14,8 +14,6 @@ protected function get_known_failures(): array { // Cases that fail in every environment. $failures = array( - 'mysql-server-suite:7923', - 'mysql-server-suite:7924', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -330,12 +328,6 @@ protected function get_known_failures(): array { 'icu-regextst:1262', 'icu-regextst:1263', 'icu-regextst:1264', - 'icu-regextst:1267', - 'icu-regextst:1268', - 'icu-regextst:1269', - 'icu-regextst:1270', - 'icu-regextst:1271', - 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', 'icu-regextst:1330', @@ -601,27 +593,6 @@ protected function get_known_failures(): array { ); } - // Before PCRE2 10.43, \w didn't match combining marks, like the vowel signs of "नमस्ते", which ICU's \w does. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:1533', - 'mysql-server-suite:1534', - 'mysql-server-suite:1553', - 'mysql-server-suite:1554', - 'mysql-server-suite:1557', - 'mysql-server-suite:1558', - 'mysql-server-suite:1701', - 'mysql-server-suite:1702', - 'mysql-server-suite:1721', - 'mysql-server-suite:1722', - 'mysql-server-suite:1725', - 'mysql-server-suite:1726', - 'mysql-server-suite:7919', - 'mysql-server-suite:7920' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index acf32376c..ae3edaeeb 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -576,19 +576,6 @@ protected function get_known_failures(): array { ); } - // Before PCRE2 10.43, \w didn't match combining marks, like the vowel signs of "नमस्ते", which ICU's \w does. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:1533', - 'mysql-server-suite:1534', - 'mysql-server-suite:1701', - 'mysql-server-suite:1702', - 'mysql-server-suite:7923', - 'mysql-server-suite:7924' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index 99c996406..726268f86 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -14,16 +14,6 @@ protected function get_known_failures(): array { // Cases that fail in every environment. $failures = array( - 'mysql-server-suite:1529', - 'mysql-server-suite:1530', - 'mysql-server-suite:1557', - 'mysql-server-suite:1558', - 'mysql-server-suite:1697', - 'mysql-server-suite:1698', - 'mysql-server-suite:1725', - 'mysql-server-suite:1726', - 'mysql-server-suite:7923', - 'mysql-server-suite:7924', 'mysql-server-suite:8349', 'mysql-server-suite:8350', 'mysql-server-suite:12325', @@ -317,8 +307,6 @@ protected function get_known_failures(): array { 'icu-regextst:1136', 'icu-regextst:1141', 'icu-regextst:1142', - 'icu-regextst:1170', - 'icu-regextst:1171', 'icu-regextst:1179', 'icu-regextst:1180', 'icu-regextst:1181', @@ -353,12 +341,6 @@ protected function get_known_failures(): array { 'icu-regextst:1262', 'icu-regextst:1263', 'icu-regextst:1264', - 'icu-regextst:1267', - 'icu-regextst:1268', - 'icu-regextst:1269', - 'icu-regextst:1270', - 'icu-regextst:1271', - 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', 'icu-regextst:1330', @@ -630,31 +612,6 @@ protected function get_known_failures(): array { ); } - // Before PCRE2 10.43, \w didn't match combining marks, like the vowel signs of "नमस्ते", which ICU's \w does. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:1525', - 'mysql-server-suite:1526', - 'mysql-server-suite:1533', - 'mysql-server-suite:1534', - 'mysql-server-suite:1553', - 'mysql-server-suite:1554', - 'mysql-server-suite:1561', - 'mysql-server-suite:1562', - 'mysql-server-suite:1693', - 'mysql-server-suite:1694', - 'mysql-server-suite:1701', - 'mysql-server-suite:1702', - 'mysql-server-suite:1721', - 'mysql-server-suite:1722', - 'mysql-server-suite:1729', - 'mysql-server-suite:1730', - 'mysql-server-suite:7919', - 'mysql-server-suite:7920' - ); - } - return $failures; } } diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index 3175a9681..d8e9f0394 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -14,8 +14,6 @@ protected function get_known_failures(): array { // Cases that fail in every environment. $failures = array( - 'mysql-server-suite:7923', - 'mysql-server-suite:7924', 'mysql-server-suite:12325', 'mysql-server-suite:12326', 'mysql-server-suite:12327', @@ -330,12 +328,6 @@ protected function get_known_failures(): array { 'icu-regextst:1262', 'icu-regextst:1263', 'icu-regextst:1264', - 'icu-regextst:1267', - 'icu-regextst:1268', - 'icu-regextst:1269', - 'icu-regextst:1270', - 'icu-regextst:1271', - 'icu-regextst:1272', 'icu-regextst:1301', 'icu-regextst:1302', 'icu-regextst:1330', @@ -601,27 +593,6 @@ protected function get_known_failures(): array { ); } - // Before PCRE2 10.43, \w didn't match combining marks, like the vowel signs of "नमस्ते", which ICU's \w does. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:1533', - 'mysql-server-suite:1534', - 'mysql-server-suite:1553', - 'mysql-server-suite:1554', - 'mysql-server-suite:1557', - 'mysql-server-suite:1558', - 'mysql-server-suite:1701', - 'mysql-server-suite:1702', - 'mysql-server-suite:1721', - 'mysql-server-suite:1722', - 'mysql-server-suite:1725', - 'mysql-server-suite:1726', - 'mysql-server-suite:7919', - 'mysql-server-suite:7920' - ); - } - return $failures; } } From a0bd826600dc1ccce6bf712dd982bc61de69e9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 13 Nov 2026 17:55:43 +0100 Subject: [PATCH 8/9] Accept ICU's names of Unicode properties ICU takes the long names of general categories, like "\p{Lowercase_Letter}", ignores case, spaces, hyphens, and underscores in names, and takes a "gc=" prefix, and an "Is" prefix, like Java. It reads "\p{...}" and "[:...:]" the same way, so "[:Lu:]" and "\p{alnum}" work, and "[:word:]" matches like "\w". PCRE has only the short names of general categories, and its POSIX classes only as "[:...:]". Translate general categories to their short names, POSIX classes in both syntaxes to PCRE's, and "[:word:]" to ICU's word class. Drop the "Is" prefix of other properties, like scripts, which go to PCRE. Keep MySQL 5.7's "[[:<:]]" and "[[:>:]]" as they are, as PCRE supports them. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 138 ++++++++++++++++-- .../tests/WP_MySQL_On_SQLite_Tests.php | 70 +++++++++ .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 131 +++-------------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 132 +++-------------- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 130 +++-------------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 131 +++-------------- 6 files changed, 284 insertions(+), 448 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index d5182fa0e..c1a460ca7 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -137,6 +137,60 @@ public static function register_for( $pdo ): self { */ private const REGEXP_WORD_CLASS = '\p{L}\p{Nl}\p{M}\p{Nd}\p{Pc}\x{200C}\x{200D}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}'; + /** + * General categories by their long names and aliases, as ICU matches them: in + * lowercase, without spaces, hyphens, and underscores. PCRE has only short names, + * and before PCRE2 10.40, not "LC". + */ + private const REGEXP_GENERAL_CATEGORIES = array( + 'other' => 'C', + 'control' => 'Cc', + 'cntrl' => 'Cc', + 'format' => 'Cf', + 'unassigned' => 'Cn', + 'privateuse' => 'Co', + 'surrogate' => 'Cs', + 'letter' => 'L', + 'casedletter' => 'L&', + 'lc' => 'L&', + 'lowercaseletter' => 'Ll', + 'modifierletter' => 'Lm', + 'otherletter' => 'Lo', + 'titlecaseletter' => 'Lt', + 'uppercaseletter' => 'Lu', + 'mark' => 'M', + 'combiningmark' => 'M', + 'spacingmark' => 'Mc', + 'enclosingmark' => 'Me', + 'nonspacingmark' => 'Mn', + 'number' => 'N', + 'decimalnumber' => 'Nd', + 'digit' => 'Nd', + 'letternumber' => 'Nl', + 'othernumber' => 'No', + 'punctuation' => 'P', + 'punct' => 'P', + 'connectorpunctuation' => 'Pc', + 'dashpunctuation' => 'Pd', + 'closepunctuation' => 'Pe', + 'finalpunctuation' => 'Pf', + 'initialpunctuation' => 'Pi', + 'otherpunctuation' => 'Po', + 'openpunctuation' => 'Ps', + 'symbol' => 'S', + 'currencysymbol' => 'Sc', + 'modifiersymbol' => 'Sk', + 'mathsymbol' => 'Sm', + 'othersymbol' => 'So', + 'separator' => 'Z', + 'lineseparator' => 'Zl', + 'paragraphseparator' => 'Zp', + 'spaceseparator' => 'Zs', + ); + + /** The POSIX classes of PCRE. */ + private const REGEXP_POSIX_CLASSES = array( 'alnum', 'alpha', 'ascii', 'blank', 'cntrl', 'digit', 'graph', 'lower', 'print', 'punct', 'space', 'upper', 'word', 'xdigit' ); + /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ private $regexp_cache = array(); @@ -1267,9 +1321,9 @@ private function regexp_check_match_type( $function_name, $match_type ) { * (UTF-8) modifier is applied unless byte-oriented matching is requested. * Case-insensitive is the default. * - * MySQL uses ICU, which differs from PCRE in some syntax, like `\N{...}` and - * property names. The known failures of the REGEXP test suites list these cases. - * Other known differences: + * MySQL uses ICU, which differs from PCRE in some syntax, like `\N{...}`, Unicode + * blocks, and Java properties. The known failures of the REGEXP test suites list + * these cases. Other known differences: * * - Text matching ignores case unless the `c` flag is passed, as the column * collation isn't known here. @@ -1286,6 +1340,8 @@ private function regexp_check_match_type( $function_name, $match_type ) { * - ICU attaches a combining mark to the character before it, so a mark after a * space doesn't start a word for `\b`. Here, it does. * - `\G` in a lookbehind doesn't always match where it does in ICU. + * - MySQL 5.7's word boundaries, `[[:<:]]` and `[[:>:]]`, work, where MySQL 8 + * rejects them. * - Data that isn't valid UTF-8 is matched byte by byte and case-sensitively, * like MySQL binary strings. Other binary values match as text, so case * sensitivity, and whether positions count bytes, can differ between rows. @@ -1417,6 +1473,11 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ // PCRE's [:punct:] also holds ASCII symbols like "+", where ICU's doesn't. '[:punct:]' => '\\p{P}', '[:^punct:]' => '\\P{P}', + + // MySQL 5.7's word boundaries go to PCRE, which supports them, as older patterns + // use them. + '[[:<:]]' => '[[:<:]]', + '[[:>:]]' => '[[:>:]]', ); if ( $without_g ) { // A position can't be both a word boundary and not one, so "\b\B" never @@ -1424,14 +1485,16 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ $tokens['\\G'] = '\\b\\B'; } - // "\w" and "\b" use ICU's word characters, except on bytes. + // "\w", "\b", and [:word:] use ICU's word characters, except on bytes. if ( ! $binary_mode ) { $word = self::REGEXP_WORD_CLASS; $tokens += array( - '\\w' => "[$word]", - '\\W' => "[^$word]", - '\\b' => "(?:(?<=[$word])(?![$word])|(? "(?:(?<=[$word])(?=[$word])|(? "[$word]", + '\\W' => "[^$word]", + '\\b' => "(?:(?<=[$word])(?![$word])|(? "(?:(?<=[$word])(?=[$word])|(? $word, + '[:^word:]' => "[^$word]", ); } @@ -1471,10 +1534,10 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ function ( $parts ) use ( $pattern, $tokens ) { $token = $parts[0]; if ( isset( $parts[1] ) ) { - return $this->regexp_translate_set( $token, $pattern, $tokens ); + return $tokens[ $token ] ?? $this->regexp_translate_set( $token, $pattern, $tokens ); } if ( '[' === $token[0] ) { - return '[' . ( $tokens[ $token ] ?? $token ) . ']'; + return $this->regexp_set_fragment( $this->regexp_translate_property( $token, $tokens ) ); } if ( isset( $token[2] ) && ( 'b' === $token[1] || 'B' === $token[1] ) ) { throw new Exception( "Invalid regular expression: $pattern." ); @@ -1592,7 +1655,7 @@ private function regexp_parse_set( array $parts, &$position, $pattern, $tokens ) // A single "-" or "&" between two sets applies to all the items before it. if ( ( '-' === $part || '&' === $part ) && 'set' === $type && '[' === substr( $next, 0, 1 ) ) { if ( '[:' === substr( $next, 0, 2 ) ) { - $right = array( $tokens[ $next ] ?? $next, true ); + $right = $this->regexp_translate_property( $next, $tokens ); ++$position; } else { $right = $this->regexp_parse_set( $parts, $position, $pattern, $tokens ); @@ -1620,7 +1683,7 @@ private function regexp_parse_set( array $parts, &$position, $pattern, $tokens ) $terms[] = $this->regexp_parse_set( $parts, $position, $pattern, $tokens ); $type = 'set'; } elseif ( preg_match( '/^(?:\[:|\\\\[pP])/', $part ) ) { - $terms[] = array( $tokens[ $part ] ?? $part, true ); + $terms[] = $this->regexp_translate_property( $part, $tokens ); $type = 'set'; } elseif ( preg_match( '/^\\\\[dDsSwWhHvV]$/', $part ) ) { // A translated class, like "[\p{L}...]", joins the set, and a negated one is an alternative. @@ -1719,6 +1782,9 @@ private function regexp_translate_token( $token, $tokens, $in_set = false ) { if ( 2 === strlen( $token ) && '\\' === $token[0] && false !== strpos( $letters, $token[1] ) ) { return $token[1]; } + if ( preg_match( '/^\\\\[pP]\{/', $token ) ) { + return $this->regexp_set_fragment( $this->regexp_translate_property( $token, $tokens ) ); + } if ( isset( $tokens[ $token ] ) ) { return $tokens[ $token ]; } @@ -1740,6 +1806,54 @@ private function regexp_translate_token( $token, $tokens, $in_set = false ) { return sprintf( '\\x{%X}', $code ); } + /** + * Translate a property, like "\p{Lowercase_Letter}" or "[:Lu:]", to PCRE. + * + * ICU takes the long names of general categories, a "gc=" prefix, and an "Is" + * prefix, like Java, and it ignores case, spaces, hyphens, and underscores in names. + * It reads both syntaxes the same way, so POSIX classes, like "alnum" or "word", + * work as "\p{...}" too, and general categories as "[:...:]". Other names, like + * scripts, go to PCRE. + * + * @param string $token The property, like "\p{...}", "\P{...}", or "[:...:]". + * @param string[] $tokens Translations of tokens. + * + * @return array The PCRE equivalent, as array( PCRE class body or fragment, whether it's a class body ). + */ + private function regexp_translate_property( $token, $tokens ) { + if ( ! preg_match( '/^(?:\\\\([pP])\{(.*)\}|\[:(\^?)(.*):\])$/s', $token, $parts ) ) { + return array( $token, true ); + } + $negated = 'P' === $parts[1] || '^' === ( $parts[3] ?? '' ); + $name = '' === $parts[1] ? $parts[4] : $parts[2]; + $loose = preg_replace( '/^(?:is|gc=|generalcategory=)(?=.)/', '', strtolower( str_replace( array( ' ', '-', '_' ), '', $name ) ) ); + + // In ICU, "\p{Uppercase}" and "\p{Lowercase}" are [:upper:] and [:lower:], so they + // ignore case the same way. + $loose = array( + 'uppercase' => 'upper', + 'lowercase' => 'lower', + )[ $loose ] ?? $loose; + + if ( in_array( $loose, self::REGEXP_POSIX_CLASSES, true ) ) { + $class = '[:' . ( $negated ? '^' : '' ) . $loose . ':]'; + } else { + if ( isset( self::REGEXP_GENERAL_CATEGORIES[ $loose ] ) ) { + $name = self::REGEXP_GENERAL_CATEGORIES[ $loose ]; + } elseif ( in_array( ucfirst( $loose ), self::REGEXP_GENERAL_CATEGORIES, true ) ) { + $name = ucfirst( $loose ); + } else { + $name = preg_replace( '/^is(?=.)/i', '', $name ); + } + $class = ( $negated ? '\\P{' : '\\p{' ) . $name . '}'; + } + + // The translations of [:upper:] and similar classes apply to their other names too. + // A negated translation, like the one of [:^word:], can't join a class. + $class = $tokens[ $class ] ?? $class; + return '[^' === substr( $class, 0, 2 ) ? array( $class, false ) : array( $class, true ); + } + /** * Check whether a string is valid UTF-8. * diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index d9c1f536d..9c5c892c8 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -383,6 +383,7 @@ public static function regexpLikeErrors() { 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'Invalid regular expression: (abc.' ), 'short escape' => array( "REGEXP_LIKE('u004', '\\\\u004')", 'Invalid regular expression: \\u004.' ), 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'Invalid regular expression: \\p{Foo}.' ), + 'property with /' => array( "REGEXP_LIKE('a', '\\\\p{a/i}')", 'Invalid regular expression: \\p{a/i}.' ), '"\\b+"' => array( "REGEXP_LIKE('b', '\\\\b+')", 'Invalid regular expression: \\b+.' ), '"\\B*"' => array( "REGEXP_LIKE('b', '\\\\B*')", 'Invalid regular expression: \\B*.' ), '"\\b{2}"' => array( "REGEXP_LIKE('b', '\\\\b{2}')", 'Invalid regular expression: \\b{2}.' ), @@ -565,6 +566,26 @@ public function testRegexpLegacyOperatorRegression() { $this->assertSame( '0', $this->last_result[0]->r ); } + /** + * @dataProvider regexpLegacyWordBoundaryCases + */ + public function testRegexpLegacyWordBoundaries( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpLegacyWordBoundaryCases() { + // MySQL 8 rejects MySQL 5.7's word boundaries, but they keep working. + return array( + 'start and end of a word' => array( "'ab cd' REGEXP '[[:<:]]cd[[:>:]]'", '1' ), + 'inside of a word' => array( "'abcd' REGEXP '[[:<:]]cd'", '0' ), + 'before a word character' => array( "'cde' REGEXP 'cd[[:>:]]'", '0' ), + 'ignoring case' => array( "'AB CD' REGEXP '[[:<:]]cd[[:>:]]'", '1' ), + 'REGEXP BINARY' => array( "'ab cd' REGEXP BINARY '[[:<:]]cd'", '1' ), + 'REGEXP_LIKE' => array( "REGEXP_LIKE('ab cd', '[[:<:]]cd')", '1' ), + ); + } + public function testRegexpLegacyOperatorNullPropagation() { $this->assertQuery( "SELECT NULL REGEXP 'a' AS r" ); $this->assertNull( $this->last_result[0]->r ); @@ -1605,6 +1626,7 @@ public function testRegexpBigIntegerColumn() { * @dataProvider regexpCodePointEscapeCases * @dataProvider regexpLiteralEscapeCases * @dataProvider regexpWordCases + * @dataProvider regexpPropertyCases */ public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { $this->assertQuery( @@ -1773,11 +1795,51 @@ public static function regexpWordCases() { '"\\w" in a set' => array( '[\\w]+', 'ab²', '²' ), '"\\W" in a set' => array( '[\\W]+', 'ab²', 'ab<²>' ), '"\\W" in a negated set' => array( '[^\\W]+', 'ab² c', '² ' ), + '"[:word:]"' => array( '[[:word:]]+', 'नमस्ते ²', '<नमस्ते> ²' ), + '"[:^word:]"' => array( '[[:^word:]]+', "ab\u{200C}cd ²", "ab\u{200C}cd< ²>" ), + '"[:word:]" outside of a set' => array( '[:word:]+', 'a²', '²' ), + '"\\p{word}"' => array( '\\p{word}+', 'a² b', '² ' ), + '"\\P{Word}"' => array( '\\P{Word}+', 'a² b', 'a<² >b' ), '"\\w" in an intersection' => array( '[\\w&&[^a]]+', 'ab²c', 'a²' ), '"\\d"' => array( '\\d+', '١٢٣ ²', '<١٢٣> ²' ), ); } + public static function regexpPropertyCases() { + return array( + 'long name' => array( '\\p{Lowercase_Letter}+', 'aBc', 'B' ), + 'long name with spaces' => array( '\\p{lowercase letter}+', 'aBc', 'B' ), + 'long name in capitals' => array( '\\p{LOWERCASELETTER}+', 'aBc', 'B' ), + 'long name with hyphens' => array( '\\p{lowercase-letter}+', 'aBc', 'B' ), + 'negated long name' => array( '\\P{Uppercase_Letter}+', 'aBc', 'B' ), + 'short name in lowercase' => array( '\\p{lu}+', 'aBc', 'ac' ), + '"Is" prefix' => array( '\\p{IsLetter}+', 'a1b', '1' ), + '"Is" and a short name' => array( '\\p{IsLu}+', 'aBc', 'ac' ), + '"gc=" prefix' => array( '\\p{gc=Lu}+', 'aBc', 'ac' ), + '"General_Category="' => array( '\\p{General_Category=Lu}+', 'aBc', 'ac' ), + 'alias "punct"' => array( '\\p{punct}+', 'a.,b+', 'a<.,>b+' ), + 'alias "digit"' => array( '\\p{IsDigit}+', 'a12²', 'a<12>²' ), + 'cased letters' => array( '\\p{Cased_Letter}+', 'aB1', '1' ), + 'short name "LC"' => array( '\\p{LC}+', 'aB1', '1' ), + '"gc=" and "LC"' => array( '\\p{gc=LC}+', 'aB1', '1' ), + '"LC" in POSIX syntax' => array( '[:LC:]+', 'aB1', '1' ), + 'property in POSIX syntax' => array( '[:Lu:]+', 'aBc', 'ac' ), + 'long name in POSIX' => array( '[:Punctuation:]+', 'a.b', 'a<.>b' ), + 'negated POSIX property' => array( '[:^Lu:]+', 'aBc', 'B' ), + 'POSIX class as "\\p"' => array( '\\p{alnum}+', 'a1-', '-' ), + 'POSIX "xdigit" as "\\p"' => array( '\\p{xdigit}+', 'fg', 'g' ), + 'POSIX class as "\\P"' => array( '\\P{alpha}+', 'a1b', 'a<1>b' ), + '"Is" and "Uppercase"' => array( '\\p{IsUppercase}+', 'aBc', 'ac' ), + 'POSIX property in a set' => array( '[[:Lu:]x]+', 'aBxc', 'ac' ), + 'POSIX class in capitals' => array( '[:Alpha:]+', 'a1b', '1' ), + 'POSIX syntax with spaces' => array( '[:Uppercase Letter:]+', 'aBc', 'ac' ), + 'POSIX syntax with "gc="' => array( '[[:gc=Lu:]]+', 'aBc', 'ac' ), + 'negated POSIX with "gc="' => array( '[[:^gc=Lu:]]+', 'aBc', 'B' ), + 'script' => array( '\\p{Greek}+', 'aαβ', 'a<αβ>' ), + '"Is" and a script' => array( '\\p{IsGreek}+', 'aαβ', 'a<αβ>' ), + ); + } + /** * @dataProvider regexpInvalidSetCases */ @@ -1863,6 +1925,13 @@ public static function regexpPosixCaseClassCases() { '\\p{Lu} in a set' => array( "REGEXP_LIKE('a', '[\\\\p{Lu}]')", '1' ), '\\p{Lu} in a negated set' => array( "REGEXP_LIKE('a', '[^\\\\p{Lu}]')", '0' ), '\\p{Lu}, intersection' => array( "REGEXP_LIKE('a', '^[\\\\p{Lu}&&[a-c]]\$')", '1' ), + 'long name, lowercase' => array( "REGEXP_LIKE('a', '\\\\p{Uppercase_Letter}')", '1' ), + 'capitals, lowercase' => array( "REGEXP_LIKE('a', '[[:Upper:]]')", '1' ), + '\\p{Upper}, lowercase' => array( "REGEXP_LIKE('a', '\\\\p{Upper}')", '1' ), + '\\p{Lower}, uppercase' => array( "REGEXP_LIKE('A', '\\\\p{Lower}')", '1' ), + '\\p{Uppercase}' => array( "REGEXP_LIKE('a', '\\\\p{Uppercase}')", '1' ), + '[:Uppercase:]' => array( "REGEXP_LIKE('a', '[[:Uppercase:]]')", '1' ), + '\\p{Upper}, c flag' => array( "REGEXP_LIKE('a', '\\\\p{Upper}', 'c')", '0' ), '\\p{Lu}, REGEXP_REPLACE' => array( "REGEXP_REPLACE('aB1', '\\\\p{Lu}', 'x')", 'xx1' ), '\\p{Ll}, operator' => array( "'A' REGEXP '\\\\p{Ll}'", '1' ), '\\p{Lu}, c flag' => array( "REGEXP_LIKE('a', '\\\\p{Lu}', 'c')", '0' ), @@ -1913,6 +1982,7 @@ public static function regexpPosixPunctCases() { 'negated class, symbol' => array( "REGEXP_LIKE('+', '[[:^punct:]]')", '1' ), 'with other set members' => array( "REGEXP_LIKE('+', '^[[:punct:]+]\$')", '1' ), 'outside of a set' => array( "REGEXP_LIKE('.', '[:punct:]')", '1' ), + 'capitals, symbol' => array( "REGEXP_LIKE('+', '[[:PUNCT:]]')", '0' ), 'REGEXP_REPLACE' => array( "REGEXP_REPLACE('a+b.c\$d,e=f!g', '[[:punct:]]', '')", 'a+bc$de=fg' ), 'operator, punctuation' => array( "'.' REGEXP '[[:punct:]]'", '1' ), 'operator, symbol' => array( "'+' REGEXP '[[:punct:]]'", '0' ), diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php index e3cd5afb4..eb3f9ae4d 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Instr_Tests.php @@ -66,62 +66,7 @@ protected function get_known_failures(): array { 'mysql-server-suite:12374', 'mysql-server-suite:12375', 'mysql-server-suite:12376', - 'mysql-server-suite:12455', - 'mysql-server-suite:12456', - 'mysql-server-suite:12457', - 'mysql-server-suite:12458', - 'mysql-server-suite:12459', - 'mysql-server-suite:12460', - 'mysql-server-suite:12461', - 'mysql-server-suite:12462', - 'mysql-server-suite:12463', - 'mysql-server-suite:12464', - 'mysql-server-suite:12465', - 'mysql-server-suite:12466', - 'mysql-server-suite:12467', - 'mysql-server-suite:12468', - 'mysql-server-suite:12469', - 'mysql-server-suite:12470', - 'mysql-server-suite:12471', - 'mysql-server-suite:12472', - 'mysql-server-suite:12473', - 'mysql-server-suite:12474', - 'mysql-server-suite:12475', - 'mysql-server-suite:12476', - 'mysql-server-suite:12477', - 'mysql-server-suite:12478', 'mysql-server-suite:12479', - 'mysql-server-suite:12480', - 'mysql-server-suite:12481', - 'mysql-server-suite:12482', - 'mysql-server-suite:12483', - 'mysql-server-suite:12484', - 'mysql-server-suite:12485', - 'mysql-server-suite:12486', - 'mysql-server-suite:12487', - 'mysql-server-suite:12488', - 'mysql-server-suite:12489', - 'mysql-server-suite:12490', - 'mysql-server-suite:12491', - 'mysql-server-suite:12492', - 'mysql-server-suite:12493', - 'mysql-server-suite:12494', - 'mysql-server-suite:12495', - 'mysql-server-suite:12496', - 'mysql-server-suite:12497', - 'mysql-server-suite:12498', - 'mysql-server-suite:12499', - 'mysql-server-suite:12500', - 'mysql-server-suite:12501', - 'mysql-server-suite:12502', - 'mysql-server-suite:12503', - 'mysql-server-suite:12504', - 'mysql-server-suite:12505', - 'mysql-server-suite:12506', - 'mysql-server-suite:12507', - 'mysql-server-suite:12508', - 'mysql-server-suite:12509', - 'mysql-server-suite:12510', 'mysql-server-suite:12589', 'mysql-server-suite:12590', 'mysql-server-suite:12591', @@ -154,8 +99,6 @@ protected function get_known_failures(): array { 'icu-regextst:147', 'icu-regextst:148', 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -212,8 +155,6 @@ protected function get_known_failures(): array { 'icu-regextst:720', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:941', - 'icu-regextst:942', 'icu-regextst:949', 'icu-regextst:950', 'icu-regextst:951', @@ -290,8 +231,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1135', - 'icu-regextst:1136', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', @@ -340,58 +279,10 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1370', - 'icu-regextst:1371', - 'icu-regextst:1372', - 'icu-regextst:1373', - 'icu-regextst:1374', - 'icu-regextst:1375', - 'icu-regextst:1376', - 'icu-regextst:1377', - 'icu-regextst:1378', - 'icu-regextst:1379', - 'icu-regextst:1380', - 'icu-regextst:1381', - 'icu-regextst:1382', - 'icu-regextst:1383', - 'icu-regextst:1384', - 'icu-regextst:1385', - 'icu-regextst:1386', - 'icu-regextst:1387', - 'icu-regextst:1388', - 'icu-regextst:1389', - 'icu-regextst:1390', - 'icu-regextst:1391', 'icu-regextst:1392', 'icu-regextst:1393', 'icu-regextst:1394', 'icu-regextst:1395', - 'icu-regextst:1396', - 'icu-regextst:1397', - 'icu-regextst:1398', - 'icu-regextst:1399', - 'icu-regextst:1400', - 'icu-regextst:1401', - 'icu-regextst:1402', - 'icu-regextst:1403', - 'icu-regextst:1404', - 'icu-regextst:1405', - 'icu-regextst:1406', - 'icu-regextst:1407', - 'icu-regextst:1408', - 'icu-regextst:1409', - 'icu-regextst:1410', - 'icu-regextst:1411', - 'icu-regextst:1412', - 'icu-regextst:1413', - 'icu-regextst:1414', - 'icu-regextst:1415', - 'icu-regextst:1416', - 'icu-regextst:1417', - 'icu-regextst:1418', - 'icu-regextst:1419', - 'icu-regextst:1420', - 'icu-regextst:1421', 'icu-regextst:1422', 'icu-regextst:1423', 'icu-regextst:1424', @@ -549,6 +440,28 @@ protected function get_known_failures(): array { 'mysql-server-suite:12452', 'mysql-server-suite:12453', 'mysql-server-suite:12454', + 'icu-regextst:1370', + 'icu-regextst:1371', + 'icu-regextst:1372', + 'icu-regextst:1373', + 'icu-regextst:1374', + 'icu-regextst:1375', + 'icu-regextst:1376', + 'icu-regextst:1377', + 'icu-regextst:1404', + 'icu-regextst:1405', + 'icu-regextst:1406', + 'icu-regextst:1407', + 'icu-regextst:1412', + 'icu-regextst:1413', + 'icu-regextst:1414', + 'icu-regextst:1415', + 'icu-regextst:1416', + 'icu-regextst:1417', + 'icu-regextst:1418', + 'icu-regextst:1419', + 'icu-regextst:1420', + 'icu-regextst:1421', 'icu-regextst:1452', 'icu-regextst:1453' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php index ae3edaeeb..1aee6bed3 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Like_Tests.php @@ -66,62 +66,6 @@ protected function get_known_failures(): array { 'mysql-server-suite:12374', 'mysql-server-suite:12375', 'mysql-server-suite:12376', - 'mysql-server-suite:12455', - 'mysql-server-suite:12456', - 'mysql-server-suite:12457', - 'mysql-server-suite:12458', - 'mysql-server-suite:12459', - 'mysql-server-suite:12460', - 'mysql-server-suite:12461', - 'mysql-server-suite:12462', - 'mysql-server-suite:12463', - 'mysql-server-suite:12464', - 'mysql-server-suite:12465', - 'mysql-server-suite:12466', - 'mysql-server-suite:12467', - 'mysql-server-suite:12468', - 'mysql-server-suite:12469', - 'mysql-server-suite:12470', - 'mysql-server-suite:12471', - 'mysql-server-suite:12472', - 'mysql-server-suite:12473', - 'mysql-server-suite:12474', - 'mysql-server-suite:12475', - 'mysql-server-suite:12476', - 'mysql-server-suite:12477', - 'mysql-server-suite:12478', - 'mysql-server-suite:12479', - 'mysql-server-suite:12480', - 'mysql-server-suite:12481', - 'mysql-server-suite:12482', - 'mysql-server-suite:12483', - 'mysql-server-suite:12484', - 'mysql-server-suite:12485', - 'mysql-server-suite:12486', - 'mysql-server-suite:12487', - 'mysql-server-suite:12488', - 'mysql-server-suite:12489', - 'mysql-server-suite:12490', - 'mysql-server-suite:12491', - 'mysql-server-suite:12492', - 'mysql-server-suite:12493', - 'mysql-server-suite:12494', - 'mysql-server-suite:12495', - 'mysql-server-suite:12496', - 'mysql-server-suite:12497', - 'mysql-server-suite:12498', - 'mysql-server-suite:12499', - 'mysql-server-suite:12500', - 'mysql-server-suite:12501', - 'mysql-server-suite:12502', - 'mysql-server-suite:12503', - 'mysql-server-suite:12504', - 'mysql-server-suite:12505', - 'mysql-server-suite:12506', - 'mysql-server-suite:12507', - 'mysql-server-suite:12508', - 'mysql-server-suite:12509', - 'mysql-server-suite:12510', 'mysql-server-suite:12589', 'mysql-server-suite:12590', 'mysql-server-suite:12591', @@ -154,8 +98,6 @@ protected function get_known_failures(): array { 'icu-regextst:147', 'icu-regextst:148', 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -212,8 +154,6 @@ protected function get_known_failures(): array { 'icu-regextst:720', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:941', - 'icu-regextst:942', 'icu-regextst:949', 'icu-regextst:950', 'icu-regextst:951', @@ -288,8 +228,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1135', - 'icu-regextst:1136', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', @@ -334,58 +272,10 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1370', - 'icu-regextst:1371', - 'icu-regextst:1372', - 'icu-regextst:1373', - 'icu-regextst:1374', - 'icu-regextst:1375', - 'icu-regextst:1376', - 'icu-regextst:1377', - 'icu-regextst:1378', - 'icu-regextst:1379', - 'icu-regextst:1380', - 'icu-regextst:1381', - 'icu-regextst:1382', - 'icu-regextst:1383', - 'icu-regextst:1384', - 'icu-regextst:1385', - 'icu-regextst:1386', - 'icu-regextst:1387', - 'icu-regextst:1388', - 'icu-regextst:1389', - 'icu-regextst:1390', - 'icu-regextst:1391', 'icu-regextst:1392', 'icu-regextst:1393', 'icu-regextst:1394', 'icu-regextst:1395', - 'icu-regextst:1396', - 'icu-regextst:1397', - 'icu-regextst:1398', - 'icu-regextst:1399', - 'icu-regextst:1400', - 'icu-regextst:1401', - 'icu-regextst:1402', - 'icu-regextst:1403', - 'icu-regextst:1404', - 'icu-regextst:1405', - 'icu-regextst:1406', - 'icu-regextst:1407', - 'icu-regextst:1408', - 'icu-regextst:1409', - 'icu-regextst:1410', - 'icu-regextst:1411', - 'icu-regextst:1412', - 'icu-regextst:1413', - 'icu-regextst:1414', - 'icu-regextst:1415', - 'icu-regextst:1416', - 'icu-regextst:1417', - 'icu-regextst:1418', - 'icu-regextst:1419', - 'icu-regextst:1420', - 'icu-regextst:1421', 'icu-regextst:1422', 'icu-regextst:1423', 'icu-regextst:1424', @@ -532,6 +422,28 @@ protected function get_known_failures(): array { 'mysql-server-suite:12452', 'mysql-server-suite:12453', 'mysql-server-suite:12454', + 'icu-regextst:1370', + 'icu-regextst:1371', + 'icu-regextst:1372', + 'icu-regextst:1373', + 'icu-regextst:1374', + 'icu-regextst:1375', + 'icu-regextst:1376', + 'icu-regextst:1377', + 'icu-regextst:1404', + 'icu-regextst:1405', + 'icu-regextst:1406', + 'icu-regextst:1407', + 'icu-regextst:1412', + 'icu-regextst:1413', + 'icu-regextst:1414', + 'icu-regextst:1415', + 'icu-regextst:1416', + 'icu-regextst:1417', + 'icu-regextst:1418', + 'icu-regextst:1419', + 'icu-regextst:1420', + 'icu-regextst:1421', 'icu-regextst:1452', 'icu-regextst:1453' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php index 726268f86..2f02a3ef7 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Replace_Tests.php @@ -68,62 +68,8 @@ protected function get_known_failures(): array { 'mysql-server-suite:12374', 'mysql-server-suite:12375', 'mysql-server-suite:12376', - 'mysql-server-suite:12455', - 'mysql-server-suite:12456', - 'mysql-server-suite:12457', - 'mysql-server-suite:12458', - 'mysql-server-suite:12459', - 'mysql-server-suite:12460', - 'mysql-server-suite:12461', - 'mysql-server-suite:12462', - 'mysql-server-suite:12463', - 'mysql-server-suite:12464', - 'mysql-server-suite:12465', - 'mysql-server-suite:12466', - 'mysql-server-suite:12467', - 'mysql-server-suite:12468', - 'mysql-server-suite:12469', - 'mysql-server-suite:12470', - 'mysql-server-suite:12471', - 'mysql-server-suite:12472', - 'mysql-server-suite:12473', - 'mysql-server-suite:12474', - 'mysql-server-suite:12475', - 'mysql-server-suite:12476', - 'mysql-server-suite:12477', - 'mysql-server-suite:12478', 'mysql-server-suite:12479', - 'mysql-server-suite:12480', - 'mysql-server-suite:12481', - 'mysql-server-suite:12482', - 'mysql-server-suite:12483', - 'mysql-server-suite:12484', - 'mysql-server-suite:12485', - 'mysql-server-suite:12486', - 'mysql-server-suite:12487', - 'mysql-server-suite:12488', - 'mysql-server-suite:12489', - 'mysql-server-suite:12490', - 'mysql-server-suite:12491', - 'mysql-server-suite:12492', - 'mysql-server-suite:12493', - 'mysql-server-suite:12494', - 'mysql-server-suite:12495', - 'mysql-server-suite:12496', - 'mysql-server-suite:12497', - 'mysql-server-suite:12498', - 'mysql-server-suite:12499', - 'mysql-server-suite:12500', - 'mysql-server-suite:12501', - 'mysql-server-suite:12502', - 'mysql-server-suite:12503', - 'mysql-server-suite:12504', - 'mysql-server-suite:12505', - 'mysql-server-suite:12506', 'mysql-server-suite:12507', - 'mysql-server-suite:12508', - 'mysql-server-suite:12509', - 'mysql-server-suite:12510', 'mysql-server-suite:12579', 'mysql-server-suite:12580', 'mysql-server-suite:12589', @@ -158,8 +104,6 @@ protected function get_known_failures(): array { 'icu-regextst:147', 'icu-regextst:148', 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', 'icu-regextst:217', 'icu-regextst:218', 'icu-regextst:219', @@ -225,8 +169,6 @@ protected function get_known_failures(): array { 'icu-regextst:895', 'icu-regextst:896', 'icu-regextst:919', - 'icu-regextst:941', - 'icu-regextst:942', 'icu-regextst:949', 'icu-regextst:950', 'icu-regextst:951', @@ -303,8 +245,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1135', - 'icu-regextst:1136', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', @@ -353,58 +293,10 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1370', - 'icu-regextst:1371', - 'icu-regextst:1372', - 'icu-regextst:1373', - 'icu-regextst:1374', - 'icu-regextst:1375', - 'icu-regextst:1376', - 'icu-regextst:1377', - 'icu-regextst:1378', - 'icu-regextst:1379', - 'icu-regextst:1380', - 'icu-regextst:1381', - 'icu-regextst:1382', - 'icu-regextst:1383', - 'icu-regextst:1384', - 'icu-regextst:1385', - 'icu-regextst:1386', - 'icu-regextst:1387', - 'icu-regextst:1388', - 'icu-regextst:1389', - 'icu-regextst:1390', - 'icu-regextst:1391', 'icu-regextst:1392', 'icu-regextst:1393', 'icu-regextst:1394', 'icu-regextst:1395', - 'icu-regextst:1396', - 'icu-regextst:1397', - 'icu-regextst:1398', - 'icu-regextst:1399', - 'icu-regextst:1400', - 'icu-regextst:1401', - 'icu-regextst:1402', - 'icu-regextst:1403', - 'icu-regextst:1404', - 'icu-regextst:1405', - 'icu-regextst:1406', - 'icu-regextst:1407', - 'icu-regextst:1408', - 'icu-regextst:1409', - 'icu-regextst:1410', - 'icu-regextst:1411', - 'icu-regextst:1412', - 'icu-regextst:1413', - 'icu-regextst:1414', - 'icu-regextst:1415', - 'icu-regextst:1416', - 'icu-regextst:1417', - 'icu-regextst:1418', - 'icu-regextst:1419', - 'icu-regextst:1420', - 'icu-regextst:1421', 'icu-regextst:1422', 'icu-regextst:1423', 'icu-regextst:1424', @@ -568,6 +460,28 @@ protected function get_known_failures(): array { 'mysql-server-suite:12452', 'mysql-server-suite:12453', 'mysql-server-suite:12454', + 'icu-regextst:1370', + 'icu-regextst:1371', + 'icu-regextst:1372', + 'icu-regextst:1373', + 'icu-regextst:1374', + 'icu-regextst:1375', + 'icu-regextst:1376', + 'icu-regextst:1377', + 'icu-regextst:1404', + 'icu-regextst:1405', + 'icu-regextst:1406', + 'icu-regextst:1407', + 'icu-regextst:1412', + 'icu-regextst:1413', + 'icu-regextst:1414', + 'icu-regextst:1415', + 'icu-regextst:1416', + 'icu-regextst:1417', + 'icu-regextst:1418', + 'icu-regextst:1419', + 'icu-regextst:1420', + 'icu-regextst:1421', 'icu-regextst:1452', 'icu-regextst:1453' ); diff --git a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php index d8e9f0394..fde039a4a 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Substr_Tests.php @@ -66,62 +66,7 @@ protected function get_known_failures(): array { 'mysql-server-suite:12374', 'mysql-server-suite:12375', 'mysql-server-suite:12376', - 'mysql-server-suite:12455', - 'mysql-server-suite:12456', - 'mysql-server-suite:12457', - 'mysql-server-suite:12458', - 'mysql-server-suite:12459', - 'mysql-server-suite:12460', - 'mysql-server-suite:12461', - 'mysql-server-suite:12462', - 'mysql-server-suite:12463', - 'mysql-server-suite:12464', - 'mysql-server-suite:12465', - 'mysql-server-suite:12466', - 'mysql-server-suite:12467', - 'mysql-server-suite:12468', - 'mysql-server-suite:12469', - 'mysql-server-suite:12470', - 'mysql-server-suite:12471', - 'mysql-server-suite:12472', - 'mysql-server-suite:12473', - 'mysql-server-suite:12474', - 'mysql-server-suite:12475', - 'mysql-server-suite:12476', - 'mysql-server-suite:12477', - 'mysql-server-suite:12478', 'mysql-server-suite:12479', - 'mysql-server-suite:12480', - 'mysql-server-suite:12481', - 'mysql-server-suite:12482', - 'mysql-server-suite:12483', - 'mysql-server-suite:12484', - 'mysql-server-suite:12485', - 'mysql-server-suite:12486', - 'mysql-server-suite:12487', - 'mysql-server-suite:12488', - 'mysql-server-suite:12489', - 'mysql-server-suite:12490', - 'mysql-server-suite:12491', - 'mysql-server-suite:12492', - 'mysql-server-suite:12493', - 'mysql-server-suite:12494', - 'mysql-server-suite:12495', - 'mysql-server-suite:12496', - 'mysql-server-suite:12497', - 'mysql-server-suite:12498', - 'mysql-server-suite:12499', - 'mysql-server-suite:12500', - 'mysql-server-suite:12501', - 'mysql-server-suite:12502', - 'mysql-server-suite:12503', - 'mysql-server-suite:12504', - 'mysql-server-suite:12505', - 'mysql-server-suite:12506', - 'mysql-server-suite:12507', - 'mysql-server-suite:12508', - 'mysql-server-suite:12509', - 'mysql-server-suite:12510', 'mysql-server-suite:12589', 'mysql-server-suite:12590', 'mysql-server-suite:12591', @@ -154,8 +99,6 @@ protected function get_known_failures(): array { 'icu-regextst:147', 'icu-regextst:148', 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', 'icu-regextst:219', 'icu-regextst:220', 'icu-regextst:221', @@ -212,8 +155,6 @@ protected function get_known_failures(): array { 'icu-regextst:720', 'icu-regextst:843', 'icu-regextst:844', - 'icu-regextst:941', - 'icu-regextst:942', 'icu-regextst:949', 'icu-regextst:950', 'icu-regextst:951', @@ -290,8 +231,6 @@ protected function get_known_failures(): array { 'icu-regextst:1130', 'icu-regextst:1131', 'icu-regextst:1132', - 'icu-regextst:1135', - 'icu-regextst:1136', 'icu-regextst:1141', 'icu-regextst:1142', 'icu-regextst:1179', @@ -340,58 +279,10 @@ protected function get_known_failures(): array { 'icu-regextst:1337', 'icu-regextst:1338', 'icu-regextst:1339', - 'icu-regextst:1370', - 'icu-regextst:1371', - 'icu-regextst:1372', - 'icu-regextst:1373', - 'icu-regextst:1374', - 'icu-regextst:1375', - 'icu-regextst:1376', - 'icu-regextst:1377', - 'icu-regextst:1378', - 'icu-regextst:1379', - 'icu-regextst:1380', - 'icu-regextst:1381', - 'icu-regextst:1382', - 'icu-regextst:1383', - 'icu-regextst:1384', - 'icu-regextst:1385', - 'icu-regextst:1386', - 'icu-regextst:1387', - 'icu-regextst:1388', - 'icu-regextst:1389', - 'icu-regextst:1390', - 'icu-regextst:1391', 'icu-regextst:1392', 'icu-regextst:1393', 'icu-regextst:1394', 'icu-regextst:1395', - 'icu-regextst:1396', - 'icu-regextst:1397', - 'icu-regextst:1398', - 'icu-regextst:1399', - 'icu-regextst:1400', - 'icu-regextst:1401', - 'icu-regextst:1402', - 'icu-regextst:1403', - 'icu-regextst:1404', - 'icu-regextst:1405', - 'icu-regextst:1406', - 'icu-regextst:1407', - 'icu-regextst:1408', - 'icu-regextst:1409', - 'icu-regextst:1410', - 'icu-regextst:1411', - 'icu-regextst:1412', - 'icu-regextst:1413', - 'icu-regextst:1414', - 'icu-regextst:1415', - 'icu-regextst:1416', - 'icu-regextst:1417', - 'icu-regextst:1418', - 'icu-regextst:1419', - 'icu-regextst:1420', - 'icu-regextst:1421', 'icu-regextst:1422', 'icu-regextst:1423', 'icu-regextst:1424', @@ -549,6 +440,28 @@ protected function get_known_failures(): array { 'mysql-server-suite:12452', 'mysql-server-suite:12453', 'mysql-server-suite:12454', + 'icu-regextst:1370', + 'icu-regextst:1371', + 'icu-regextst:1372', + 'icu-regextst:1373', + 'icu-regextst:1374', + 'icu-regextst:1375', + 'icu-regextst:1376', + 'icu-regextst:1377', + 'icu-regextst:1404', + 'icu-regextst:1405', + 'icu-regextst:1406', + 'icu-regextst:1407', + 'icu-regextst:1412', + 'icu-regextst:1413', + 'icu-regextst:1414', + 'icu-regextst:1415', + 'icu-regextst:1416', + 'icu-regextst:1417', + 'icu-regextst:1418', + 'icu-regextst:1419', + 'icu-regextst:1420', + 'icu-regextst:1421', 'icu-regextst:1452', 'icu-regextst:1453' ); From e1c310b4d61a4732516608f598913ce16365ac13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Sat, 14 Nov 2026 18:21:01 +0100 Subject: [PATCH 9/9] Keep REGEXP comments out of the translation A translation in a "(?#...)" comment could end the comment early, as "\b" becomes a group with ")", or raise an error, as for an invalid set. So "a(?#\b)b" failed to compile, where MySQL matches "ab". Read each comment as one token, and replace it with an empty comment. Like in ICU, a "\Q" in a comment quotes its text up to "\E", so "(?#\Q)a" has no end, which is an error. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 29 ++++++++++++++----- .../tests/WP_MySQL_On_SQLite_Tests.php | 22 ++++++++++++-- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index c1a460ca7..6f5c9c65a 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php @@ -1342,6 +1342,9 @@ private function regexp_check_match_type( $function_name, $match_type ) { * - `\G` in a lookbehind doesn't always match where it does in ICU. * - MySQL 5.7's word boundaries, `[[:<:]]` and `[[:>:]]`, work, where MySQL 8 * rejects them. + * - A `#` comment of the `x` flag is translated like the rest of the pattern, so + * an invalid set or a repeated `\b` in it is an error, and a `\Q` in it quotes + * the text after it. * - Data that isn't valid UTF-8 is matched byte by byte and case-sensitively, * like MySQL binary strings. Other binary values match as text, so case * sensitivity, and whether positions count bytes, can differ between rows. @@ -1451,16 +1454,16 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w /** * Translate a MySQL regex pattern to PCRE syntax. * - * Splits the pattern into quoted text, sets, escapes, POSIX classes, and other - * characters, so that a translation applies only to a whole token. + * Splits the pattern into quoted text, comments, sets, escapes, POSIX classes, and + * other characters, so that a translation applies only to a whole token. * * @param string $pattern The regex pattern. * @param bool $case_insensitive Whether the pattern ignores case by default. * @param bool $binary_mode Whether the pattern matches bytes instead of UTF-8 characters. * @param bool $without_g Whether "\G" never matches. * - * @throws Exception If the pattern can't be split, or it has an invalid set or a - * repeated word boundary. + * @throws Exception If the pattern can't be split, or it has an invalid set, a + * comment without an end, or a repeated word boundary. * @return string Pattern safe to wrap in slash delimiters. */ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_mode, $without_g ) { @@ -1480,8 +1483,7 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ '[[:>:]]' => '[[:>:]]', ); if ( $without_g ) { - // A position can't be both a word boundary and not one, so "\b\B" never - // matches. Unlike "(?!)", it has no ")" to end a "(?#...)" comment. + // "\b\B" never matches, as no position is both a word boundary and not one. $tokens['\\G'] = '\\b\\B'; } @@ -1518,6 +1520,10 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ } /* + * A "(?#...)" comment is one token, so that no translation changes it. Like in + * ICU, a "\Q" in it quotes the text up to "\E", which can hold its ")", but "\\Q" + * is an escaped backslash and a "Q". + * * A set, with its nested sets, is one token, as ICU's sets differ from PCRE's. * Like ICU, "[:" starts a POSIX class if the next ":" is followed by "]", and a * set otherwise. ICU reads a POSIX class outside of a set, as in "[:alpha:]", as @@ -1530,12 +1536,19 @@ private function regexp_translate_pattern( $pattern, $case_insensitive, $binary_ * "{" after it is one token, so that it is an error, like in ICU. */ $translated = preg_replace_callback( - '/\\\\Q.*?(?:\\\\E|\z)|\[:\^?[^:]*:\]|(\[\^?+\]?+(?:\\\\Q.*?(?:\\\\E|\z)|\\\\c.|\\\\.|\[:\^?[^:]*:\]|(?1)|[^\\\\\[\]])*+\])|' . self::REGEXP_CODE_POINT_ESCAPE . '|\\\\[pP]\{[^}\\\\]*\}|\\\\[bB][*+?{]|\\\\.|[\/\0]/s', + '/\\\\Q.*?(?:\\\\E|\z)|\(\?#(?:\\\\Q.*?(?:\\\\E|\z)|\\\\[^)]|[^)])*+\)|\(\?#|\[:\^?[^:]*:\]|(\[\^?+\]?+(?:\\\\Q.*?(?:\\\\E|\z)|\\\\c.|\\\\.|\[:\^?[^:]*:\]|(?1)|[^\\\\\[\]])*+\])|' . self::REGEXP_CODE_POINT_ESCAPE . '|\\\\[pP]\{[^}\\\\]*\}|\\\\[bB][*+?{]|\\\\.|[\/\0]/s', function ( $parts ) use ( $pattern, $tokens ) { $token = $parts[0]; if ( isset( $parts[1] ) ) { return $tokens[ $token ] ?? $this->regexp_translate_set( $token, $pattern, $tokens ); } + if ( '(?#' === $token ) { + // The comment has no end, as its ")" is missing or quoted. + throw new Exception( "Invalid regular expression: $pattern." ); + } + if ( '(' === $token[0] ) { + return '(?#)'; + } if ( '[' === $token[0] ) { return $this->regexp_set_fragment( $this->regexp_translate_property( $token, $tokens ) ); } @@ -1996,7 +2009,7 @@ private function regexp_matches( $pattern, $match_type, $byte_mode, $subject, $o /* * Only PCRE's "\K" can start a match before the search, and then the next * search would find the same match forever. The translation reads "\K" as - * "K", except after a "\Q" in a comment. + * "K", except after a "\Q" in an extended comment. */ if ( $match[0][1] < $offset ) { throw new Exception( 'Invalid regular expression: ' . $pattern . '.' ); diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index 9c5c892c8..be2b0111b 100644 --- a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php +++ b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php @@ -383,6 +383,8 @@ public static function regexpLikeErrors() { 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'Invalid regular expression: (abc.' ), 'short escape' => array( "REGEXP_LIKE('u004', '\\\\u004')", 'Invalid regular expression: \\u004.' ), 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'Invalid regular expression: \\p{Foo}.' ), + 'open comment' => array( "REGEXP_LIKE('a', 'a(?#')", 'Invalid regular expression: a(?#.' ), + 'comment quote' => array( "REGEXP_LIKE('a', '(?#\\\\Q)a')", 'Invalid regular expression: (?#\\Q)a.' ), 'property with /' => array( "REGEXP_LIKE('a', '\\\\p{a/i}')", 'Invalid regular expression: \\p{a/i}.' ), '"\\b+"' => array( "REGEXP_LIKE('b', '\\\\b+')", 'Invalid regular expression: \\b+.' ), '"\\B*"' => array( "REGEXP_LIKE('b', '\\\\B*')", 'Invalid regular expression: \\B*.' ), @@ -1528,9 +1530,10 @@ public function testRegexpEscapedKInLookbehind() { * @dataProvider regexpQuoteInCommentCases */ public function testRegexpEscapedKAfterQuoteInComment( $sql, $pattern ) { - // The translation reads a "\Q" in a comment as quoted text, so a later "\K" - // reaches PCRE. A match that starts before the search is then an error, not an - // endless loop. + // The translation reads a "\Q" in an extended comment as quoted text, so a later + // "\K" reaches PCRE. A match that starts before the search is then an error, not an + // endless loop. In a "(?#...)" comment, "\Q" quotes the ")", like in ICU, so the + // comment has no end, which is an error too. $this->assertQueryError( 'SELECT ' . sprintf( $sql, $this->engine->quote( $pattern ) ), "Invalid regular expression: $pattern." @@ -1627,6 +1630,7 @@ public function testRegexpBigIntegerColumn() { * @dataProvider regexpLiteralEscapeCases * @dataProvider regexpWordCases * @dataProvider regexpPropertyCases + * @dataProvider regexpCommentCases */ public function testRegexpIcuSyntax( $pattern, $subject, $expected ) { $this->assertQuery( @@ -1840,6 +1844,18 @@ public static function regexpPropertyCases() { ); } + public static function regexpCommentCases() { + return array( + 'escape in a comment' => array( 'a(?#\b)b', 'ab', '' ), + 'set in a comment' => array( '(?#[a--])a', 'a', '' ), + 'quoted ")" in a comment' => array( '(?#\Q)a\E)b', 'ab', 'a' ), + 'slash in a comment' => array( '(?#/)a', 'a', '' ), + 'comment before a digit' => array( '(a)\1(?#)0', 'aa0', '' ), + 'comment in a set' => array( '[(?#)]+', '#)a', '<#)>a' ), + '"\\\\Q" in a comment' => array( '(?#\\\\Q)a', 'a', '' ), + ); + } + /** * @dataProvider regexpInvalidSetCases */