From bb7acda45ec66f2f38f71ad05084748f9cd20144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Mon, 23 Nov 2026 16:43:37 +0100 Subject: [PATCH 1/5] Add a lightweight ICU to PCRE regex translator MySQL reads REGEXP patterns with ICU, and the driver runs them with PCRE. The two differ in sets, escapes, line ends, word characters, and POSIX classes. WP_ICU_Regex_Translator splits a pattern into tokens with one regex. A token either means the same in PCRE, or it has a translation. Any other text is rejected, so PCRE-only syntax, like "(?R)" or "\K", and ICU syntax that isn't supported, like set operations or the "x" flag, never reach PCRE. The REGEXP functions don't use the class yet. --- .../src/icu/class-wp-icu-regex-translator.php | 441 +++++++++ packages/mysql-on-sqlite/src/load.php | 1 + .../icu/WP_ICU_Regex_Translator_Tests.php | 924 ++++++++++++++++++ 3 files changed, 1366 insertions(+) create mode 100644 packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php create mode 100644 packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php diff --git a/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php new file mode 100644 index 000000000..5916bbbdd --- /dev/null +++ b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php @@ -0,0 +1,441 @@ +). The i, m, s, and d flags can also be set inline. + * Legacy MySQL patterns may use [[:<:]], [[:>:]], and literal braces. + * + * Unsupported ICU syntax + * + * - Nested sets, set operations, and negated classes that expand to several + * items inside a set, such as [\W_]. + * - Unicode properties beyond short general categories (Lu), scripts (Greek), + * and POSIX classes (alpha). + * - Escaped letters without a meaning, which ICU reads literally, such as \y. + * - Flags x and w, named characters (\N{name}), backreferences above \9, + * quantified anchors, and empty \Q\E. + * + * Known differences from ICU + * + * - Case-insensitive matching does not equate "ß" with "ss". The Lu, Ll, Lt, + * upper, and lower classes match every cased letter, including dotless "ı". + * - [:upper:] and [:lower:] miss cased symbols such as "Ⅷ". + * - \s, \h, [:space:], and [:blank:] also match U+180E. Word boundaries + * consider combining marks and format characters that ICU skips. + * - In dotall mode, "." matches CR and LF separately. In multiline mode, "^" + * skips the position between them. Grapheme clusters (\X) follow PCRE's rules. + * - Before PCRE 10.40, alphabetic classes miss some combining vowel signs. + * - PCRE accepts backreferences in lookbehinds and named backreferences before + * their group. It limits explicit repetition counts to 65535, lookbehinds to + * a fixed length before 10.43, and group names to 32 characters before 10.44. + */ +class WP_ICU_Regex_Translator { + // The characters that end a line in ICU. + private const LINE_ENDS = '\n\x0B\f\r\x85\x{2028}\x{2029}'; + + // PCRE counts "²" as a word character. ICU excludes it. + private const WORD = '\p{L}\p{M}\p{Nd}\p{Nl}\p{Pc}\x{200C}\x{200D}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}'; + + // PCRE class bodies for ICU's POSIX classes. + private const POSIX_CLASSES = array( + 'alnum' => '\p{Alphabetic}\p{Nd}', + 'alpha' => '\p{Alphabetic}', + 'ascii' => '\x00-\x7F', + 'blank' => '\h', + 'cntrl' => '\p{Cc}', + 'digit' => '\d', + 'graph' => '\p{L}\p{M}\p{N}\p{P}\p{S}\p{Cf}\p{Co}', + 'lower' => '\p{Ll}', + 'print' => '\p{L}\p{M}\p{N}\p{P}\p{S}\p{Cf}\p{Co}\p{Zs}', + 'punct' => '\p{P}', + 'space' => '\s', + 'upper' => '\p{Lu}', + 'word' => self::WORD, + 'xdigit' => '\p{Nd}A-Fa-f\x{FF21}-\x{FF26}\x{FF41}-\x{FF46}', + ); + + // Translations for ".", "^", and "$" under the active flags. + private const NOT_IN_CRLF = '(?!(?<=\r)\n)'; + private const LINES = array( + '.' => '[^' . self::LINE_ENDS . ']', + '.d' => '[^\n]', + '.s' => '[\s\S]', + '.sd' => '[\s\S]', + '^' => '\A', + '^d' => '\A', + '^m' => '(?:\A|(?<=[' . self::LINE_ENDS . '])(?!\z))' . self::NOT_IN_CRLF, + '^md' => '(? '(?=(?:\r\n|[' . self::LINE_ENDS . '])?\z)' . self::NOT_IN_CRLF, + '$d' => '(?=\n?\z)', + '$m' => '(?![^' . self::LINE_ENDS . '])' . self::NOT_IN_CRLF, + '$md' => '(?![^\n])', + ); + + // Escapes outside of a set, and MySQL 5.7's word boundaries. + private const ESCAPES = array( + 'A' => '\A', + 'b' => '(?(?<=[' . self::WORD . '])(?![' . self::WORD . '])|(?=[' . self::WORD . ']))', + 'B' => '(?(?<=[' . self::WORD . '])(?=[' . self::WORD . '])|(?![' . self::WORD . ']))', + 'G' => '\G', + 'R' => '(?>\r\n|[' . self::LINE_ENDS . '])', + 'X' => '\X', + 'z' => '\z', + 'Z' => self::LINES['$'], + '[[:<:]]' => '(?:]]' => '(?<=[' . self::WORD . '])(?![' . self::WORD . '])', + ); + + private const QUOTE = '\\\\Q(?!\\\\E)(?:[^\\\\]++|\\\\(?!E))*+'; + private const ESCAPE = '\\\\(?:[pP]\{[^}]*\}|x\{[0-9A-Fa-f]{1,6}\}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|0[0-3][0-7]{2}|0[0-7]{1,2}|c[\x00-\x7F]|k<[A-Za-z][A-Za-z0-9]*>|[1-9](?!\d)|[^Q0-9])'; + private const POSIX = '\[:\^?[A-Za-z]+:\]'; + private const SET_ITEM = self::POSIX . '|' . self::QUOTE . '\\\\E|' . self::ESCAPE . '|-(?!-)|&(?!&)|[^\[\]\\\\&-]++'; + private const SET = '(?!\[:[^:]*:\])\[\^?+\]?+(?:' . self::SET_ITEM . ')*+\]'; + private const INTERVAL = '\{\d+(?:,\d*)?\}'; + private const QUANTIFIER = '((?:[*+?]|' . self::INTERVAL . ')[+?]?)?'; + private const GROUP = '\((?:\?(?:[:=!>]|<[=!]|<[A-Za-z][A-Za-z0-9]*>|#[^)\\\\]*\)|(?=[imsdu-])([imsdu]*)-?([imsdu]*)([:)])))?'; + private const BRACE = '(\}|(?!' . self::INTERVAL . ')\{)'; + private const TOKEN = '/(?:[^\\\\\[(){}|^$.*+?\/\x00]++|' . self::QUOTE . '(?:\\\\E|\z)|' . self::ESCAPE . '|' . self::POSIX . '|' . self::SET . '|[.)\/\x00])' . self::QUANTIFIER . '|' . self::GROUP . '|' . self::BRACE . '|\[\[:[<>]:\]\]|[\s\S]/'; + + // Capture groups in TOKEN. + private const CAPTURE_QUANTIFIER = 1; + private const CAPTURE_FLAGS_ON = 2; + private const CAPTURE_FLAGS_OFF = 3; + private const CAPTURE_FLAG_DELIMITER = 4; + private const CAPTURE_BRACE = 5; + + // Cap the input size before expanding tokens such as word boundaries into longer PCRE patterns. + private const MAX_LENGTH = 65535; + + /** + * Active ICU flags. + * + * @var string + */ + private $flags; + + /** + * Saved flags and repeatability for each open group. + * + * @var array[] + */ + private $groups = array(); + + /** + * Whether \G in the input pattern must fail. + * + * @var bool + */ + private $without_g; + + /** + * Translate an ICU regular expression to a PCRE pattern. + * + * @param string $pattern The ICU regular expression. + * @param string $flags ICU flags: i (ignore case), m (multiline), s (dotall), d (Unix lines). + * @param bool $without_g Disable \G when starting past the previous match or at a nonzero initial offset. + * + * @throws DomainException On unsupported syntax, flags, or a translation limit. + * @return string A pattern for the preg_*() functions. It can still fail to compile. + */ + public static function translate( $pattern, $flags = '', $without_g = false ) { + if ( strlen( $pattern ) > self::MAX_LENGTH || strspn( $flags, 'imsd' ) !== strlen( $flags ) ) { + throw new DomainException( 'Unsupported regular expression length or flags.' ); + } + $translator = new self(); + $translator->flags = $flags; + $translator->without_g = $without_g; + $translated = self::replace( self::TOKEN, array( $translator, 'translate_token' ), $pattern ); + + // "X" stops PHP 7.3 and 7.4 from reading an unknown property as literal text. + return '/' . $translated . '/uX' . ( false !== strpos( $flags, 'i' ) ? 'i' : '' ); + } + + /** + * Translate one token and update the state for the next token. + * + * @param string[] $parts Captures from TOKEN. + * @return string The PCRE text. + */ + private function translate_token( $parts ) { + $token = $parts[0]; + $quantifier = $parts[ self::CAPTURE_QUANTIFIER ] ?? ''; + $item = substr( $token, 0, strlen( $token ) - strlen( $quantifier ) ); + + switch ( $item[0] ) { + case '\\': + // A position, like "\b", can't be repeated. + if ( isset( $item[1] ) && ( '' === $quantifier || false === strpos( 'AbBGzZ', $item[1] ) ) ) { + return $this->translate_escape( substr( $item, 1 ), false ) . $quantifier; + } + break; + case '[': + if ( isset( self::ESCAPES[ $item ] ) ) { + return self::ESCAPES[ $item ]; + } elseif ( preg_match( '/^\[:[^:]*:\]$/', $item ) ) { + // ICU also accepts a POSIX class on its own, as in "[:digit:]". + return $this->translate_property( trim( $item, '[:^]' ), '^' === $item[2], false ) . $quantifier; + } elseif ( isset( $item[1] ) ) { + return $this->translate_set( $item ) . $quantifier; + } + break; + case '(': + $delimiter = $parts[ self::CAPTURE_FLAG_DELIMITER ] ?? ''; + if ( '' !== $delimiter ) { + // Pass case sensitivity to PCRE. The other flags affect how we translate the pattern. + $old = $this->flags; + $this->flags = str_replace( str_split( $parts[ self::CAPTURE_FLAGS_OFF ] . '-' ), '', $old . $parts[ self::CAPTURE_FLAGS_ON ] ); + if ( ':' === $delimiter ) { + $this->groups[] = array( $old, true ); + } + return '(?' . ( false !== strpos( $this->flags, 'i' ) ? 'i' : '-i' ) . $delimiter; + } elseif ( '(?#' === substr( $item, 0, 3 ) ) { + return '(?#)'; + } + // A look-around can't be repeated. + $is_look_around = false !== strpbrk( $item, '=!' ); + $this->groups[] = array( $this->flags, ! $is_look_around ); + return $item; + case ')': + if ( $this->groups ) { + list( $this->flags, $is_repeatable ) = array_pop( $this->groups ); + if ( '' === $quantifier || $is_repeatable ) { + return $token; + } + } + break; + case '.': + return $this->line_pattern( '.' ) . $quantifier; + case '^': + case '$': + return $this->line_pattern( $item ); + case '{': + case '}': + // An interval with nothing to repeat is an error. + if ( '' !== ( $parts[ self::CAPTURE_BRACE ] ?? '' ) ) { + return '\\' . $item; + } + break; + case '/': + return '\/' . $quantifier; + case "\0": + return '\x00' . $quantifier; + case '|': + return '|'; + case '*': + case '+': + case '?': + break; + default: + return $token; + } + throw new DomainException( "Unsupported regular expression syntax: $token" ); + } + + /** + * Translate an escape. + * + * @param string $escape The escape, without its backslash. + * @param bool $in_set Whether the escape is in a set. + * @return string The PCRE text. + */ + private function translate_escape( $escape, $in_set ) { + $letter = $escape[0]; + $lower = strtolower( $letter ); + $rest = substr( $escape, 1 ); + if ( 'Q' === $letter && '' !== $rest ) { + return preg_quote( preg_replace( '/\\\\E$/', '', $rest ), '/' ); + } elseif ( 'p' === $lower && '' !== $rest ) { + return $this->translate_property( substr( $rest, 1, -1 ), 'P' === $letter, $in_set ); + } elseif ( 'k' === $letter && '' !== $rest && ! $in_set ) { + return '\\' . $escape; + } elseif ( '' !== $rest && 'k' !== $letter ) { + // For \cX, ICU takes the low five bits of X. The tokenizer accepts ASCII X. + if ( 'c' === $letter ) { + $code = ord( $rest ) & 0x1F; + } else { + $code = '0' === $letter ? octdec( $rest ) : hexdec( trim( $rest, '{}' ) ); + } + return sprintf( '\x{%X}', $code ); + } elseif ( ! preg_match( '/^[A-Za-z0-9]/', $letter ) || false !== strpos( 'aefnrt', $letter ) ) { + // Preserve escaped punctuation and shared escapes such as \n. + return '\\' . $letter; + } elseif ( false !== strpos( 'dhsvw', $lower ) ) { + $body = 'w' === $lower ? self::WORD : '\\' . $lower; + return $this->class_body( $body, $lower !== $letter, $in_set ); + } elseif ( ! $in_set ) { + if ( 'G' === $letter && $this->without_g ) { + return '(?!)'; + } elseif ( isset( self::ESCAPES[ $letter ] ) ) { + return self::ESCAPES[ $letter ]; + } elseif ( false !== strpos( '123456789', $letter ) ) { + return '\g{' . $letter . '}'; + } + } + throw new DomainException( "Unsupported regular expression syntax: \\$escape" ); + } + + /** + * Translate a set, like "[a-z[:digit:]]". + * + * Preserve character ranges. Elsewhere, "-" and "&" may be literals or ICU set operators. + * + * @param string $set The set, with its brackets. + * @return string The PCRE class. + */ + private function translate_set( $set ) { + $start = '^' === $set[1] ? 2 : 1; + $previous = ''; + $body = self::replace( + // Capture the next class escape, opening bracket, or end of the set to disambiguate "-" and "&". + '/(?:' . self::SET_ITEM . '|\])(?=(\z|\[|\\\\[dDhHsSvVwWpP])?)/', + function ( $parts ) use ( &$previous ) { + $item = $parts[0]; + $next = $parts[1] ?? null; + $last = $previous; + if ( '-' === $item || '&' === $item ) { + $previous = $item; + if ( '-' === $item && 'character' === $last && null === $next ) { + return '-'; + } + + /* + * ICU reads a "-" or "&" between two sets as a set operator. It rejects a + * range that ends with a class, and after a literal "&", it starts a range + * at an earlier character. + */ + $is_operator = 'set' === $last && '[' === $next; + $is_ends_class = '-' === $item && isset( $next[1] ) && ( 'character' === $last || '&' === $last ); + $is_after_amp = '-' === $item && null === $next && '&' === $last; + if ( $is_operator || $is_ends_class || $is_after_amp ) { + throw new DomainException( "Unsupported regular expression syntax: $item in a set" ); + } + return '\\' . $item; + } elseif ( '[' === $item[0] ) { + $previous = 'set'; + return $this->translate_property( trim( $item, '[:^]' ), '^' === $item[2], true ); + } + if ( '\\' === $item[0] ) { + $previous = 'character'; + if ( preg_match( '/^\\\\(?:[pP]\{|[dDhHsSvVwW]$)/', $item ) ) { + $previous = isset( $item[2] ) ? 'set' : 'class'; + } + return $this->translate_escape( substr( $item, 1 ), true ); + } + $previous = 'character'; + return strtr( + $item, + array( + '/' => '\/', + "\0" => '\x00', + ']' => '\]', + ) + ); + }, + substr( $set, $start, -1 ) + ); + return substr( $set, 0, $start ) . $body . ']'; + } + + /** + * Translate a property name, like "Lu", "Greek", or "alpha". + * + * @param string $name The name. + * @param bool $negated Whether the property is negated. + * @param bool $in_set Whether the property is in a set. + * @return string The PCRE class, or its body when the property is in a set. + */ + private function translate_property( $name, $negated, $in_set ) { + $key = strtolower( $name ); + if ( false !== strpos( $this->flags, 'i' ) && in_array( $key, array( 'lu', 'll', 'lt', 'upper', 'lower' ), true ) ) { + // Lu, Ll, and Lt expand to all cased letters. + $body = '\p{L&}'; + } elseif ( isset( self::POSIX_CLASSES[ $key ] ) ) { + $body = self::POSIX_CLASSES[ $key ]; + } elseif ( preg_match( '/^[a-z]{1,2}$/', $key ) ) { + // A general category. PCRE rejects the ones that it doesn't know. + $body = '\p{' . ( 'lc' === $key ? 'L&' : ucfirst( $key ) ) . '}'; + } elseif ( preg_match( '/^[A-Z][a-z]{2,}(?:_[A-Z][a-z]+)*$/', $name ) && ! in_array( $name, array( 'Any', 'Xan', 'Xps', 'Xsp', 'Xuc', 'Xwd' ), true ) ) { + // From PCRE 10.40, a bare script name can mean Script_Extensions. Request Script explicitly. + $body = '\p{' . ( self::has_pcre_10_40() ? 'sc:' : '' ) . $name . '}'; + } else { + throw new DomainException( "Unsupported regular expression property: $name" ); + } + return $this->class_body( $body, $negated, $in_set ); + } + + /** + * Format a class for use on its own or inside another set. + * + * @param string $body The class body. + * @param bool $negated Whether the class is negated. + * @param bool $in_set Whether the class is in a set. + * @return string The PCRE class, or its body when the class is in a set. + */ + private function class_body( $body, $negated, $in_set ) { + if ( ! self::has_pcre_10_40() ) { + // Older PCRE versions lack Alphabetic. Approximate it with letters, letter numbers, and enclosed letters. + $body = str_replace( '\p{Alphabetic}', '\p{L}\p{Nl}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}', $body ); + } + if ( ! $in_set ) { + return '[' . ( $negated ? '^' : '' ) . $body . ']'; + } elseif ( ! $negated ) { + return $body; + } elseif ( ! preg_match( '/^\\\\(?:[dhsv]|p\{(?!Alphabetic)[^}]*\})$/', $body ) ) { + // Inside a set, PCRE can negate only a single class item. Alphabetic expands + // to several items on older versions, so reject its negation here on all versions. + throw new DomainException( 'Unsupported regular expression syntax: a negated class in a set' ); + } + $body[1] = strtoupper( $body[1] ); + return $body; + } + + /** + * Select a line pattern for the active flags. + * + * @param string $token A dot or a line anchor. + * @return string The PCRE fragment. + */ + private function line_pattern( $token ) { + $flag = '.' === $token[0] ? 's' : 'm'; + $key = $token; + if ( false !== strpos( $this->flags, $flag ) ) { + $key .= $flag; + } + if ( false !== strpos( $this->flags, 'd' ) ) { + $key .= 'd'; + } + return self::LINES[ $key ]; + } + + /** + * Replace matched tokens. A PCRE limit makes preg_replace_callback() return null, + * which would become an empty pattern when the caller adds delimiters. + * + * @param string $regex The regex that matches a token. + * @param callable $callback The function that translates a token. + * @param string $text The text. + * @return string The text with its tokens replaced. + */ + private static function replace( $regex, $callback, $text ) { + $replaced = preg_replace_callback( $regex, $callback, $text ); + if ( null === $replaced ) { + throw new DomainException( 'Unsupported regular expression: it is too complex.' ); + } + return $replaced; + } + + /** + * Check whether PCRE knows binary properties and the "sc:" prefix. + * + * @return bool Whether PCRE is 10.40 or newer. + */ + private static function has_pcre_10_40() { + return version_compare( explode( ' ', PCRE_VERSION )[0], '10.40', '>=' ); + } +} diff --git a/packages/mysql-on-sqlite/src/load.php b/packages/mysql-on-sqlite/src/load.php index 93e6b4f09..d05f12054 100644 --- a/packages/mysql-on-sqlite/src/load.php +++ b/packages/mysql-on-sqlite/src/load.php @@ -19,6 +19,7 @@ require_once __DIR__ . '/mysql/class-wp-mysql-lexer.php'; require_once __DIR__ . '/mysql/class-wp-mysql-parser.php'; +require_once __DIR__ . '/icu/class-wp-icu-regex-translator.php'; require_once __DIR__ . '/sqlite/class-wp-sqlite-connection.php'; require_once __DIR__ . '/sqlite/class-wp-sqlite-configurator.php'; require_once __DIR__ . '/sqlite/class-wp-sqlite-driver.php'; diff --git a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php new file mode 100644 index 000000000..35131cd0e --- /dev/null +++ b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php @@ -0,0 +1,924 @@ +". data_first_match() uses ICU 79.1. + */ +class WP_ICU_Regex_Translator_Tests extends TestCase { + /** + * @dataProvider data_matches + */ + public function test_matches( string $pattern, string $flags, string $subject, string $expected ): void { + $this->assertSame( $expected, $this->replace_matches( WP_ICU_Regex_Translator::translate( $pattern, $flags ), $subject ) ); + } + + /** + * Each row gives the pattern, flags, subject, and subject with matches marked. + */ + public function data_matches(): array { + return array( + // Literals and escapes. + array( 'abc', '', 'xabcxabc', 'xx' ), + array( 'a/b', '', 'a/b', '' ), + array( 'a b', '', 'a b', '' ), + array( 'a#b', '', 'a#b', '' ), + array( 'é', '', 'éa', '<é>a' ), + array( '😀', '', 'a😀', 'a<😀>' ), + array( ']', '', 'a]', 'a<]>' ), + array( '\\_', '', '_', '<_>' ), + array( '\\-', '', '-', '<->' ), + array( '\\é', '', 'é', '<é>' ), + array( '\\a', '', "\x07", "<\x07>" ), + array( '\\e', '', "\e", "<\e>" ), + array( '\\f', '', "\f", "<\f>" ), + array( '\\n', '', "\n", "<\n>" ), + array( '\\r', '', "\r", "<\r>" ), + array( '\\t', '', "\t", "<\t>" ), + array( '\\cA', '', "\x01", "<\x01>" ), + array( '\\c1', '', "\x11", "<\x11>" ), + array( '\\x41', '', 'A', '' ), + array( '\\x4', '', "\x04", "<\x04>" ), + array( '\\x{41}', '', 'A', '' ), + array( '\\x{1F600}', '', '😀', '<😀>' ), + array( '\\u0041', '', 'A', '' ), + array( '\\u00e9', '', 'é', '<é>' ), + array( '\\U0001F600', '', '😀', '<😀>' ), + array( '\\0101', '', 'A', '' ), + array( '\\07', '', "\x07", "<\x07>" ), + array( '\\0377', '', 'ÿ', '<ÿ>' ), + array( '\\0400', '', ' 0', '< 0>' ), + array( '\\x41*', '', 'AAb', '<>b<>' ), + array( '\\Qa.b\\E', '', 'a.b', '' ), + array( '\\Qa.b', '', 'a.b', '' ), + array( '\\Qab\\E*', '', 'abb', '' ), + array( '\\Q(\\E', '', '(', '<(>' ), + array( '\\.', '', 'a.', 'a<.>' ), + array( '\\*', '', '*', '<*>' ), + array( '\\\\', '', '\\', '<\\>' ), + array( '\\/', '', '/', '' ), + // Quantifiers. + array( 'a*', '', 'aab', '<>b<>' ), + array( 'a+', '', 'aab', 'b' ), + array( 'a?', '', 'aab', '<>b<>' ), + array( 'a*?', '', 'aab', '<>a<>a<>b<>' ), + array( 'a+?', '', 'aab', 'b' ), + array( 'a??', '', 'aab', '<>a<>a<>b<>' ), + array( 'a*+a', '', 'aaa', 'aaa' ), + array( 'a++a', '', 'aaa', 'aaa' ), + array( 'a?+a', '', 'aa', '' ), + array( 'a{2}', '', 'aaa', 'a' ), + array( 'a{1,2}', '', 'aaa', '' ), + array( 'a{2,}', '', 'aaa', '' ), + array( 'a{1,2}?', '', 'aaa', '' ), + array( 'a{1,2}+a', '', 'aaa', '' ), + array( 'a{0}b', '', 'ab', 'a' ), + array( 'a{007}', '', 'aaaaaaa', '' ), + array( 'é*', '', 'éé', '<éé><>' ), + array( 'ab*', '', 'abb', '' ), + array( ']*', '', ']]', '<]]><>' ), + array( '\\P{Lu}+\\D', '', 'xa', '' ), + array( '\\P{Lu}*\\D', '', 'xa', '' ), + array( '\\P{Lu}+?\\P{Ll}', '', 'xA', '' ), + array( '\\P{Nd}+\\P{Lu}', '', 'xa', '' ), + array( '\\D+\\P{Lu}', '', 'xa', '' ), + array( '\\D*\\P{Ll}', '', 'AB', '' ), + array( '[:^Lu:]+\\D', '', 'xa', '' ), + // Groups. + array( '(a)(b)', '', 'ab', '' ), + array( '(?:a)(b)', '', 'ab', '' ), + array( '(?>a|ab)c', '', 'abc', 'abc' ), + array( '(a)|(b)', '', 'ab', '' ), + array( '(?a)', '', 'a', '' ), + array( '(?a)(?b)', '', 'ab', '' ), + array( 'a(?=b)', '', 'abac', 'bac' ), + array( 'a(?!b)', '', 'abac', 'abc' ), + array( '(?<=a)b', '', 'abcb', 'acb' ), + array( '(?' ), + array( '(?<=a|bc)d', '', 'bcdad', 'bca' ), + array( '(?#comment)a', '', 'a', '' ), + array( 'a(?#comment)b', '', 'ab', '' ), + array( '()', '', 'a', '<|>a<|>' ), + array( '(|a)', '', 'a', '<|>a<|>' ), + array( '(a*)*', '', 'aa', '<|>' ), + array( '(?:a|b)+', '', 'abc', 'c' ), + // Backreferences. + array( '(a)\\1', '', 'aa', '' ), + array( '(a)(b)\\2', '', 'abb', '' ), + array( '(a)(b)\\1\\2', '', 'abab', '' ), + array( '\\1(a)', '', 'aa', 'aa' ), + array( '(?a)\\k', '', 'aa', '' ), + array( '(a)\\1', 'i', 'aA', '' ), + array( '(a)|b\\1', '', 'b', 'b' ), + // Flags. + array( 'a', 'i', 'A', '' ), + array( 'a(?i)b', '', 'aB', '' ), + array( 'a(?i)b', '', 'AB', 'AB' ), + array( '(?i)a(?-i)b', '', 'AB', 'AB' ), + array( '(?i)a(?-i)b', '', 'Ab', '' ), + array( '(a(?i)b)c', '', 'aBc', '' ), + array( '(a(?i)b)c', '', 'aBC', 'aBC' ), + array( '(?i:a)b', '', 'Ab', '' ), + array( '(?i:a)b', '', 'AB', 'AB' ), + array( '(?-i:a)b', 'i', 'aB', '' ), + array( '(?-i:a)b', 'i', 'AB', 'AB' ), + array( 'a(?i)b|c', '', 'C', '' ), + array( '(?u)a', '', 'a', '' ), + array( '(?-)a', '', 'a', '' ), + array( '(?im-s:a.)', '', "A\n", "A\n" ), + array( '(?s)a.', '', "a\n", "" ), + array( '(?s:a.)a.', '', "a\na\n", "a\na\n" ), + array( '(?m)a$', '', "a\nb", "\nb" ), + array( '(?d)a$', '', "a\r", "a\r" ), + array( '(?d).', '', "\r", "<\r>" ), + array( '(?d-d).', '', "\r", "\r" ), + // Sets. + array( '[abc]', '', 'xabc', 'x' ), + array( '[^abc]', '', 'xabc', 'abc' ), + array( '[a-c]', '', 'xabc', 'x' ), + array( '[é-ë]', '', 'êz', '<ê>z' ), + array( '[😀-😂]', '', '😁', '<😁>' ), + array( '[]a]', '', ']a', '<]>' ), + array( '[^]a]', '', ']ab', ']a' ), + array( '[-a]', '', '-a', '<->' ), + array( '[a-]', '', '-a', '<->' ), + array( '[a-c-e]', '', 'be-d', '<->d' ), + array( '[\\w-z]', '', '-z.', '<->.' ), + array( '[\\d-a]', '', '1-ab', '<1><->b' ), + array( '[\\p{Lu}-z]', '', 'A-z', '<->' ), + array( '[[:digit:]-z]', '', '1-z', '<1><->' ), + array( '[\\n]', '', "\nn", "<\n>n" ), + array( '[\\x41-\\x43]', '', 'ABCD', 'D' ), + array( '[a-\\x63]', '', 'abcd', 'd' ), + array( '[\\u00e9]', '', 'é', '<é>' ), + array( '[\\Qa-c\\E]', '', 'a-cb', '<->b' ), + array( '[\\Q]\\E]', '', ']', '<]>' ), + array( '[.*+?(){}|^$]', '', '.*+?(){}|^$', '<.><*><+><(><)><{><}><|><^><$>' ), + array( '[\\^a]', '', '^a', '<^>' ), + array( '[a^]', '', '^a', '<^>' ), + array( '[/]', '', '/', '' ), + array( '[a]*', '', 'aa', '<>' ), + array( '[a&b]', '', 'a&bc', '<&>c' ), + array( '[&a]', '', '&a', '<&>' ), + array( '[a&]', '', '&a', '<&>' ), + array( '[\\s\\S]', '', "a\n", "<\n>" ), + array( '[\\P{L}]', '', 'a1', 'a<1>' ), + array( '[^\\P{L}]', '', 'a1', '1' ), + array( '[\\h]', '', "a \t", "a< ><\t>" ), + array( '[\\H]', '', 'a ', ' ' ), + array( '[\\v]', '', "a\n", "a<\n>" ), + array( '[\\V]', '', "a\n", "\n" ), + array( '(?i)[^a]', '', 'aAb', 'aA' ), + array( '(?i)[ß]', '', 'ßs', '<ß>s' ), + // POSIX classes. + array( '[[:alpha:]]', '', 'a1', '1' ), + array( '[:alpha:]', '', 'a1', '1' ), + array( '[:^alpha:]', '', 'a1', 'a<1>' ), + array( '[:alpha:]+', '', 'ab1', '1' ), + array( '[^:alpha:]', '', 'a1', 'a<1>' ), + array( '[:abc]', '', 'a:d', '<:>d' ), + array( '[[:alnum:]]', '', 'a1-', '<1>-' ), + array( '[[:blank:]]', '', "a \t\n", "a< ><\t>\n" ), + array( '[[:cntrl:]]', '', "a\x01", "a<\x01>" ), + array( '[[:digit:]]', '', 'a1', 'a<1>' ), + array( '[[:graph:]]', '', 'a ', ' ' ), + array( '[[:lower:]]', '', 'aA', 'A' ), + array( '[[:print:]]', '', "a\x01", "\x01" ), + array( '[[:punct:]]', '', 'a.+', 'a<.>+' ), + array( '[[:space:]]', '', "a \n", "a< ><\n>" ), + array( '[[:upper:]]', '', 'aA', 'a' ), + array( '[[:upper:]]', 'i', 'aA1', '1' ), + array( '[[:lower:]]', 'i', 'aA1', '1' ), + array( '[[:word:]]', '', 'a_-', '<_>-' ), + array( '[[:xdigit:]]', '', 'afg', 'g' ), + array( '[[:Lu:]]', '', 'aA', 'a' ), + array( '[[:alpha:][:digit:]]', '', 'a1-', '<1>-' ), + array( '[[:alpha:]-z]', '', 'a-1', '<->1' ), + // Properties. + array( '\\p{L}', '', 'a1', '1' ), + array( '\\P{L}', '', 'a1', 'a<1>' ), + array( '\\p{Lu}', '', 'aA', 'a' ), + array( '\\p{lu}', '', 'aA', 'a' ), + array( '\\p{ASCII}', '', 'aé', 'é' ), + array( '\\p{word}', '', 'a-', '-' ), + array( '\\p{Greek}', '', 'aα', 'a<α>' ), + array( '\\P{Greek}', '', 'aα', 'α' ), + array( '\\p{Han}', '', '日。', '<日>。' ), + array( '\\p{Old_Italic}', '', '𐌀a', '<𐌀>a' ), + array( '\\p{Lu}', 'i', 'aA1', '1' ), + array( '\\P{Lu}', 'i', 'aA1', 'aA<1>' ), + array( '\\p{Ll}', 'i', 'aA1', '1' ), + array( '(?i)\\p{Lu}', '', 'aA1', '1' ), + array( '(?i:\\p{Lu})\\p{Lu}', '', 'aa', 'aa' ), + array( '(?i:\\p{Lu})\\p{Lu}', '', 'aA', '' ), + array( '(?-i)\\p{Lu}', 'i', 'aA', 'a' ), + array( '\\p{Nd}', '', 'a٣', 'a<٣>' ), + array( '\\p{Zs}', '', "a\u{A0}", "a<\u{A0}>" ), + // Shorthand classes. + array( '\\d', '', 'a1٣', 'a<1><٣>' ), + array( '\\D', '', 'a1', '1' ), + array( '\\w', '', 'a1_-', '<1><_>-' ), + array( '\\w', '', "e\u{301}", "<\u{301}>" ), + array( '\\w', '', "\u{200D}", "<\u{200D}>" ), + array( '\\w', '', 'Ⅷ', '<Ⅷ>' ), + array( '\\w', '', 'Ⓐ', '<Ⓐ>' ), + array( '\\w', '', '²½', '²½' ), + array( '\\W', '', 'a-', 'a<->' ), + array( '\\s', '', "a \t\n\u{A0}\u{2003}\u{85}", "a< ><\t><\n><\u{A0}><\u{2003}><\u{85}>" ), + array( '\\v', '', "a\n\v\f\r\u{85}\u{2028}\u{2029}", "a<\n><\v><\f><\r><\u{85}><\u{2028}><\u{2029}>" ), + array( '\\V', '', "a\n", "\n" ), + array( '\\R', '', "a\r\n\n\r\u{2028}", "a<\r\n><\n><\r><\u{2028}>" ), + array( '\\R*', '', "\r\n\r\n", "<\r\n\r\n><>" ), + array( '\\X', '', "e\u{301}a", "" ), + // Line terminators. + array( '^a', '', "b\na", "b\na" ), + array( '^a', 'm', "b\na", "b\n" ), + array( '^', 'm', "a\nb\n", "<>a\n<>b\n" ), + array( '^', 'm', "a\r\nb\r\n", "<>a\r\n<>b\r\n" ), + array( '^', 'm', "\n\n", "<>\n<>\n" ), + array( '^', 'md', "a\nb\n", "<>a\n<>b\n<>" ), + array( '^', 'md', "a\rb", "<>a\rb" ), + array( '(?m)^', '', "a\r\nb", "<>a\r\n<>b" ), + array( '^a|^b', 'm', "a\r\nb", "\r\n" ), + array( '^\\s*', 'm', "a\r\n b", "<>a\r\n< >b" ), + array( 'a$', '', "a\n", "\n" ), + array( 'a$', '', "a\r", "\r" ), + array( 'a$', '', "a\r\n", "\r\n" ), + array( 'a$', '', "a\n\n", "a\n\n" ), + array( 'a$', '', "a\n\r", "a\n\r" ), + array( 'a$', '', "a\u{85}", "\u{85}" ), + array( 'a$', '', "a\u{2028}", "\u{2028}" ), + array( 'a$', '', "a\v", "\v" ), + array( '$', '', "a\n", "a<>\n<>" ), + array( '$', '', "a\r\n", "a<>\r\n<>" ), + array( '$', 'm', "a\nb\n", "a<>\nb<>\n<>" ), + array( '$', 'm', "a\r\nb\r\n", "a<>\r\nb<>\r\n<>" ), + array( '$', 'd', "a\n", "a<>\n<>" ), + array( '$', 'd', "a\r\n", "a\r<>\n<>" ), + array( '$', 'md', "a\nb\r\n", "a<>\nb\r<>\n<>" ), + array( 'a\\Z', '', "a\n", "\n" ), + array( 'a\\Z', '', "a\r\n", "\r\n" ), + array( 'a\\Z', 'd', "a\r", "\r" ), + array( 'a\\z', '', "a\n", "a\n" ), + array( 'a\\z', '', 'a', '' ), + array( '\\Aa', '', 'aa', 'a' ), + array( '\\Aa', 'm', "b\na", "b\na" ), + array( '.', '', "a\nb\r\u{85}\u{2028}\u{2029}\v\fc", "\n\r\u{85}\u{2028}\u{2029}\v\f" ), + array( '.', 'd', "a\nb\r\u{85}\u{2028}c", "\n<\r><\u{85}><\u{2028}>" ), + array( '.*', 's', "a\r\nb", "<>" ), + array( '.+', 's', "a\r\nb", "" ), + array( '.*?', 's', "a\r\n", "<>a<>\r<>\n<>" ), + array( '(?<=.)b', 's', "\r\nb", "\r\n" ), + array( '^.$', '', "\r\n", "\r\n" ), + // Word boundaries. + array( '\\bfoo\\b', '', 'foo foobar barfoo foo', ' foobar barfoo ' ), + array( '\\b', '', 'foo bar', '<>foo<> <>bar<>' ), + array( '\\B', '', 'foo bar', 'f<>o<>o b<>a<>r' ), + array( '\\b', '', 'é a', '<>é<> <>a<>' ), + array( '\\b', '', '日本語 x', '<>日本語<> <>x<>' ), + array( '\\b', '', '_a', '<>_a<>' ), + array( '\\b', '', 'a1', '<>a1<>' ), + array( '\\b', '', "e\u{301}x y", "<>e\u{301}x<> <>y<>" ), + array( '\\b', '', "e\u{301}\u{302} y", "<>e\u{301}\u{302}<> <>y<>" ), + array( '\\b', '', "\u{FEFF}a", "\u{FEFF}<>a<>" ), + array( '\\b', '', '²a', '²<>a<>' ), + // Case folding. + array( 'K', 'i', "k\u{212A}", "<\u{212A}>" ), + array( "\u{212A}", 'i', 'kK', '' ), + array( 's', 'i', 'Sſ', '<ſ>' ), + array( 'σ', 'i', 'Σς', '<Σ><ς>' ), + array( 'ς', 'i', 'Σσ', '<Σ><σ>' ), + array( 'é', 'i', 'É', '<É>' ), + array( 'ı', 'i', 'iI', 'iI' ), + array( 'i', 'i', 'ıİ', 'ıİ' ), + array( 'ß', '', 'SS', 'SS' ), + array( 'ss', '', 'ß', 'ß' ), + array( 'ss*', 'i', 'ß', 'ß' ), + array( 'ss+', 'i', 'ß', 'ß' ), + array( 'ss?', 'i', 'ß', 'ß' ), + array( 'ss{1}', 'i', 'ß', 'ß' ), + array( 's', 'i', 'ß', 'ß' ), + array( '[s]', 'i', 'ß', 'ß' ), + array( '(?i)ss(?-i)ss', '', 'ßß', 'ßß' ), + ); + } + + /** + * @dataProvider data_first_match + */ + public function test_first_match( string $pattern, string $subject, ?string $expected ): void { + $found = preg_match( WP_ICU_Regex_Translator::translate( $pattern ), $subject, $match ); + $this->assertSame( $expected, 1 === $found ? $match[0] : null ); + } + + public function data_first_match(): array { + return array( + array( 'abc+', 'abccc', 'abccc' ), + array( 'a|bc', 'bc', 'bc' ), + array( '', 'abc', '' ), + array( 'a||b', 'c', '' ), + array( '(ab)+', 'abab', 'abab' ), + array( '(?:ab){2,3}', 'ababab', 'ababab' ), + array( '(?>a|ab)c', 'abc', null ), + array( 'a++a', 'aaa', null ), + array( 'a*?b', 'aaab', 'aaab' ), + array( 'a{2}?', 'aaa', 'aa' ), + array( 'a{' . str_repeat( '0', 4096 ) . '2}', 'aaa', 'aa' ), + array( 'a?+a', 'a', null ), + array( 'a(?=b)', 'ab', 'a' ), + array( 'a(?!b)', 'ac', 'a' ), + array( '(?<=ab{2})c', 'abbc', 'c' ), + array( '(?a+)b\k', 'aaabaaa', 'aaabaaa' ), + array( '(a)(b)\2\1', 'abba', 'abba' ), + array( '\1(a)', 'aa', null ), + array( '(a)?b', 'b', 'b' ), + array( '(?:(a)|(b))+', 'ab', 'ab' ), + array( '(a|(b))*', 'ba', 'ba' ), + array( '(?u)a', 'a', 'a' ), + array( '(?-i:a)', 'a', 'a' ), + array( '\Q.a[~]\E+', '.a[~]]', '.a[~]]' ), + array( '\Qabc', 'abc', 'abc' ), + array( 'a*\Q?\E', 'aaa?', 'aaa?' ), + array( 'a*\Q+\E', 'aaa+', 'aaa+' ), + array( '(\Q)\E)', ')', ')' ), + array( '\Q\Q\E', '\Q', '\Q' ), + array( '\Qquoted\E', 'quoted', 'quoted' ), + array( '\Qé😀\E+', 'é😀😀', 'é😀😀' ), + array( '[\Q]-&\E]+', ']-&', ']-&' ), + array( '(?d).', "\r", "\r" ), + array( '(?s).|.', "\n", "\n" ), + array( 'a(?s).|.', "\n", "\n" ), + array( '(?s:a.)|.', "\n", null ), + array( 'a(?m)$', "a\nb", 'a' ), + array( '(?m)^$', '', '' ), + array( 'a$', "a\r\n", 'a' ), + array( 'a\Z', "a\r\n", 'a' ), + array( '\n(?m)^', "\n", null ), + array( '\r(?m)$\n', "\r\n", null ), + array( '\R+', "\r\n\u{2028}", "\r\n\u{2028}" ), + array( '\R\n', "\r\n", null ), + array( '\h+', "\t\u{a0}", "\t\u{a0}" ), + array( '\s', "\v", "\v" ), + array( '\s', "\u{85}", "\u{85}" ), + array( '\w+', "é\u{301}\u{2160}\u{200c}", "é\u{301}\u{2160}\u{200c}" ), + array( '\d+', '١٢', '١٢' ), + array( '\D+', 'é!', 'é!' ), + array( '[\D]+', 'é!', 'é!' ), + array( '[a\D]+', '1a!', 'a!' ), + array( '\u0061\U0001F600\x{62}\x63', 'a😀bc', 'a😀bc' ), + array( '\xA', "\n", "\n" ), + array( '\x414\u0061b\U00000063d', 'A4abcd', 'A4abcd' ), + array( '\x{000061}\x{10FFFF}', "a\u{10ffff}", "a\u{10ffff}" ), + array( '[\u0061-\x{63}]+', 'abc', 'abc' ), + array( '\0777', '?7', '?7' ), + array( '\00', "\0", "\0" ), + array( "a\0b", "a\0b", "a\0b" ), + array( '\a\e\f\n\r\t\cA', "\x07\x1b\f\n\r\t\x01", "\x07\x1b\f\n\r\t\x01" ), + array( 'a~b\\\\c', 'a~b\\c', 'a~b\\c' ), + array( ']', ']', ']' ), + array( 'a]', 'a]', 'a]' ), + array( '[def]]', 'abcdef', null ), + array( '[def]]', 'abcdef]]', 'f]' ), + array( '2(]*)?$\1', '2', '2' ), + array( '[a-z]+', 'foo', 'foo' ), + array( '[😀-🙏]+', '😀😁', '😀😁' ), + array( '[]a]+', ']a', ']a' ), + array( '[^]a]+', 'bc', 'bc' ), + array( '[-a&]+', '-a&', '-a&' ), + array( '(?dm)\n^', "\n", "\n" ), + array( '(?<=abc{2})d', 'abccd', 'd' ), + array( '(?<=(?:a|b){2})c', 'abc', 'c' ), + array( '\A[a\D]+\z', str_repeat( 'a', 64 ) . '1', null ), + array( '[abcdefghijk-z]+', 'ijxyz', 'ijxyz' ), + array( '[:digit:]+', '١٢', '١٢' ), + array( '[[:^digit:]]+', 'ab', 'ab' ), + ); + } + + /** + * Syntax that MySQL 5.7 and MariaDB accept, and MySQL 8 rejects. + * + * @dataProvider data_legacy_syntax + */ + public function test_legacy_syntax( string $pattern, string $subject, string $expected ): void { + $this->assertSame( $expected, $this->replace_matches( WP_ICU_Regex_Translator::translate( $pattern ), $subject ) ); + } + + public function data_legacy_syntax(): array { + return array( + array( '[[:<:]]word[[:>:]]', 'a word, words, sword', 'a , words, sword' ), + array( '[[:<:]]', 'ab cd', '<>ab <>cd' ), + array( '[[:>:]]', 'ab cd', 'ab<> cd<>' ), + array( '[[:<:]]a|b[[:>:]]', 'ab ba', ' ba' ), + array( 'a:[0-9]+:{', 'a:12:{i:0;}', 'i:0;}' ), + array( '{"id":[0-9]+}', '{"id":42}', '<{"id":42}>' ), + array( 'x{2}}', 'xx}', '' ), + array( 'a{,3}', 'a{,3} aaa', ' aaa' ), + array( 'a{x}', 'a{x}', '' ), + array( '{', '{}', '<{>}' ), + array( '}', '{}', '{<}>' ), + ); + } + + /** + * @dataProvider data_known_differences + */ + public function test_known_differences( string $pattern, string $flags, string $subject, string $mysql, string $expected ): void { + $actual = $this->replace_matches( WP_ICU_Regex_Translator::translate( $pattern, $flags ), $subject ); + $this->assertSame( $expected, $actual ); + $this->assertNotSame( $mysql, $actual ); + } + + /** + * Each row gives the pattern, flags, subject, MySQL result, and expected translation result. + */ + public function data_known_differences(): array { + return array( + array( '\\p{Lt}', 'i', 'Dždža', '<Dž><dž>a', '<Dž><dž>' ), + array( '\\s', '', "\u{180E}", "\u{180E}", "<\u{180E}>" ), + array( '\\S', '', "a \u{180E}", " <\u{180E}>", " \u{180E}" ), + array( '\\h', '', "a \t\n\u{A0}\u{180E}", "a< ><\t>\n<\u{A0}>\u{180E}", "a< ><\t>\n<\u{A0}><\u{180E}>" ), + array( '\\H', '', "a \u{180E}", " <\u{180E}>", " \u{180E}" ), + array( '^|x', 'm', "a\r\nb", "<>a\r<>\n<>b", "<>a\r\n<>b" ), + array( '.', 's', "a\r\nb", "<\r\n>", "<\r><\n>" ), + array( '.', 'sd', "a\r\nb", "<\r\n>", "<\r><\n>" ), + array( '.*\\n', 's', "a\r\n", "a\r<\n>", "" ), + array( '.+\\n', 's', "\r\n\r\n", "\r\n\r\n", "<\r\n\r\n>" ), + array( '.?', 's', "\r\n", "<\r\n><>", "<\r><\n><>" ), + array( '.{2}', 's', "\r\na", "<\r\na>", "<\r\n>a" ), + array( '^.$', 's', "\r\n", "<\r\n>", "\r\n" ), + array( '\\b', '', "-\u{301}x", "-\u{301}<>x<>", "-<>\u{301}x<>" ), + array( '\\B', '', "-\u{301}x", "<>-<>\u{301}x", "<>-\u{301}<>x" ), + array( '\\b', '', "\u{301}x", "\u{301}<>x<>", "<>\u{301}x<>" ), + array( '\\b', '', "a\u{AD}b", "<>a\u{AD}b<>", "<>a<>\u{AD}<>b<>" ), + array( '\\B', '', "a\u{AD}b", "a<>\u{AD}<>b", "a\u{AD}b" ), + array( '\\b', '', "😀\u{FE0F}a", "😀\u{FE0F}<>a<>", "😀<>\u{FE0F}a<>" ), + array( '\\b', '', "\u{200D}a", "\u{200D}<>a<>", "<>\u{200D}a<>" ), + array( 'ss', 'i', 'ßẞSSss', '<ß><ẞ>', 'ßẞ' ), + array( 'ß', 'i', 'ßẞSSss', '<ß><ẞ>', '<ß><ẞ>SSss' ), + array( 'ẞ', 'i', 'ßẞSSss', '<ß><ẞ>', '<ß><ẞ>SSss' ), + array( 'strasse', 'i', 'Straße', '', 'Straße' ), + array( 'STRASSE', 'i', 'Straße', '', 'Straße' ), + array( 'straße', 'i', 'STRASSE', '', 'STRASSE' ), + array( '\\x{DF}', 'i', 'SS', '', 'SS' ), + array( 'asss*', 'i', 'aß', '', 'aß' ), + array( 'ß+', 'i', 'ssß', '', 'ss<ß>' ), + array( 'aß+', 'i', 'assß', '', 'assß' ), + array( '(?i)ss(?-i)ss', '', 'ßss', '<ßss>', 'ßss' ), + ); + } + + /** + * @dataProvider data_unsupported_syntax + */ + public function test_unsupported_syntax( string $pattern ): void { + $this->expectException( DomainException::class ); + WP_ICU_Regex_Translator::translate( $pattern ); + } + + public function data_unsupported_syntax(): array { + return $this->as_cases( + array( + '\\y', + '\\K', + '\\C', + '\\g{1}', + '\\Q\\E', + 'a\\Eb', + '^*a', + '$*a', + '^+a', + '^(?#c)*a', + 'a(?#c)*', + '\\p{IsAssigned}+\\P{Lu}', + '(a)\\10', + '(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\\10', + '(?x) a b ', + "(?x)a # comment\n b", + '(?x)a #', + '(?x)a\\ b', + '(?x)a *', + '(?x)a { 1 , 2 }', + '(?x)[a b]', + '(?x)[a\\ b]', + '(?x)\\Qa b\\E', + '(?x)\\p{ L u }', + '(?x: a ) b', + "(?x)a\u{2028}b\u{200E}c", + "(?x)a\u{3000}b", + '(?x)(?#c)a', + '(?x)( ?:a)', + '[\\b]', + '[\\1]', + '[\\y]', + '[a-\\p]', + '[a[bc]d]', + '[a[^b]]', + '[^a[b]]', + '[^[^a]]', + '[[a][b]]+', + '[a-c&&b-d]', + '[a-c&&[b-d]]', + '[a-c--b]', + '[a-c--[b]]', + '[[a-c]-[b]]', + '[[a-c]&[b]]', + '[a-c&&b-d&&c-e]', + '[a-e--b--c]', + '[a-c&&b-d--c]', + '[a-c--b&&a]', + '[a[b]&&b]', + '[[a][b]-[b]]', + '[[a][b]&[b]]', + '[1[a]&[b]]', + '[[a-c]-[b]d]', + '[[a-c]-[b]\\d]', + '[^a-c&&b]', + '[\\w&&\\D]', + '[\\W\\d]', + '[^\\W]', + '[\\w\\W]', + '[\\W\\w]+', + '[a\\w\\W]+', + '[[\\w][\\W]]+', + '[^\\w\\W]', + '[\\w\\W&&a]', + '[\\w\\W--a]', + '[a--\\p{L}]', + '[\\p{L}--[a]]', + '[a][&-c]', + '(?i)[[a-c]--[B]]', + '[[:^alpha:]]', + '[:a\\x41:]', + '\\p{uppercase letter}', + '\\p{UPPERCASE-LETTER}', + '\\p{gc=Lu}', + '\\p{General_Category=Letter}', + '\\p{IsLu}', + '\\p{IsTitleCase}', + '\\P{IsAssigned}', + '\\p{Any}', + '\\P{Any}', + '\\p{greek}', + '\\p{IsGreek}', + '\\p{Script=Greek}', + '\\p{sc=Han}', + '\\p{old italic}', + '^*', + '(a)\12', + '\j\K\C', + '\E', + 'a\Q\E+', + '(?x)\Q #[]() \E', + '(?x)[\Q ^ \E]', + '(?x)[a-\Qz\E]', + 'a(?# a comment )+', + '(?x) a # comment' . "\n" . 'b', + '(?x)[a b]+', + '(?x)[a # comment' . "\n" . 'b]+', + '(?x:a b) c', + '(?x)a\ b', + '(?x)a{ 2 , 3 }', + '(?x)( ? : a )', + '(?x)(?< a >x)\k< a >', + '(?x)a( ?# comment )+', + '(?x)\p {L}', + '(?x)[[a] & [b]]', + '(?x)[a - b]', + '(?x)[a & & a]', + '(?x)[ :digit: ]', + "(?x)a\u{200e}b", + "(?x)a\u{00a0}b", + '[a-z&&[^aeiou]]+', + '[[a-z]-[aeiou]]+', + '[[a-z]&[def]]+', + '[a-z-[aeiou]]+', + '[a&&[b]c]', + '[[a]&[b]c]', + '[a[b]&[b]]', + '[a[b]-[b]]', + '[ab-\p{L}]', + '[a-\h]', + '[[a-z]-[bc]\p{L}]', + '[[a-z]&[bc]\d]', + '[[a-z]&[bc]d]', + '[[a-z]-[bc]&\p{L}]', + '[ab--bc]', + '[a--b&&b]', + '[[a][b][c]]+', + '[class[concat][union][not]]+', + '[^[a-c][d-f]]+', + '[^[^a-c]]+', + str_repeat( '[a', 64 ) . 'b' . str_repeat( ']', 64 ), + '[^' . str_repeat( '[a', 63 ) . 'b' . str_repeat( ']', 64 ), + '[' . str_repeat( '[a]', 2048 ) . ']+', + '[\b\A\1]+', + '[\p{L}&&\P{Lu}]+', + '\p{General_Category=Decimal_Number}+', + '\p{gC=lU}+', + '\p{upper-case_letter}+', + ) + ); + } + + /** + * Reject PCRE extensions that ICU rejects or interprets differently. + * + * @dataProvider data_pcre_syntax + */ + public function test_pcre_syntax_is_rejected( string $pattern ): void { + $this->expectException( DomainException::class ); + WP_ICU_Regex_Translator::translate( $pattern ); + } + + public function data_pcre_syntax(): array { + return $this->as_cases( + array( + '(*ACCEPT)', + '(*FAIL)', + '(*F)', + '(*COMMIT)', + '(*PRUNE)', + '(*SKIP)', + '(*THEN)', + '(*MARK:x)', + '(*:x)', + '(*UTF8)', + '(*UTF)', + '(*UCP)', + '(*NO_JIT)', + '(*LIMIT_MATCH=1)', + '(*ANY)', + '(*CRLF)', + '(*BSR_ANYCRLF)', + '(*NOTEMPTY)', + '(*NO_START_OPT)', + '(*NO_AUTO_POSSESS)', + 'a(*ACCEPT)b', + 'a|(*FAIL)', + '(*pla:a)', + '(*atomic:a)', + '(?R)', + '(?0)', + '(?1)', + '(a)(?1)', + '(?+1)(a)', + '(a)(?-1)', + '(?a)(?&n)', + '(?a)(?P>n)', + '(a)(?(1)b|c)', + '(?(DEFINE)a)', + '(?(?=a)b)', + '(?C)', + '(?C1)a', + '(?|a|b)', + '(?Pa)', + '(?\'n\'a)', + '(?a)(?P=n)', + '(?a)\\k\'n\'', + '(?a)\\k{n}', + '(a)\\g1', + '(a)\\g{1}', + '(a)\\g{-1}', + '(a)\\g<1>', + '(?U)a', + '(?J)a', + '(?n)a', + '(?^)a', + '(?xx)a', + '(?a)a', + '(?r)a', + '(?X)a', + '\\N', + 'a\\N+', + '\\N{U+41}', + '\\K', + 'a\\Kb', + '(?<=\\Ka)', + '\\C', + '\\o{101}', + '\\E', + 'a\\Eb', + '\\pL', + '\\PL', + '\\p{L&}', + '\\p{^L}', + '\\p{Xan}', + '\\p{Xwd}', + '\\p{Xsp}', + '\\p{Any}', + '[[.a.]]', + '[[=a=]]', + '(?x)', + '(?<1a>x)', + '\\x', + '\\xg', + '\\x{}', + '\\x{00000041}', + '\\0', + '\\08', + '\\10', + '\\400', + '(a)\\10', + '(?)', + '(?[a])', + '(?[ [a-z] - [aeiou] ])', + ) + ); + } + + /** + * @dataProvider data_invalid_patterns + */ + public function test_invalid_patterns_do_not_compile( string $pattern ): void { + try { + $compiled = WP_ICU_Regex_Translator::translate( $pattern ); + } catch ( DomainException $e ) { + $this->addToAssertionCount( 1 ); + return; + } + + // Check the compile error without also reporting PHP's warning. + set_error_handler( static function () {} ); + try { + $result = preg_match( $compiled, '' ); + } finally { + restore_error_handler(); + } + $this->assertFalse( $result ); + $this->assertSame( PREG_INTERNAL_ERROR, preg_last_error() ); + } + + public function data_invalid_patterns(): array { + return $this->as_cases( + array( + '(', + ')', + 'a)', + '(a', + '[', + '[a', + '[]', + '[^]', + '*', + '+a', + 'a**', + 'a+*', + 'a{2}{3}', + 'a{2,1}', + '^*', + '$+', + '\\b+', + '\\A?', + '(?=a)*', + '(?<=a)+', + '(?!a){2}', + '\\', + 'a\\', + '[z-a]', + '[a-\\d]', + '[--a]', + '[a--]', + '[&&a]', + '[a&&]', + '\\p{Nope}', + '\\p{Greekish}', + '\\p{L', + '\\p', + '(?x)(?y)', + '\\2(a)', + '\\k', + '\\x{110000}', + '\\x{D800}', + '(?#', + '(?#a', + '(?i', + '(?z)a', + 'a{65536}', + '[[:nope:]]', + '[[:alpha:]', + '(?<=a*)b', + "\xC0\xAF", + "\xED\xA0\x80", + ) + ); + } + + /** + * @dataProvider data_output + */ + public function test_output( string $pattern, string $flags, string $expected ): void { + $this->assertSame( $expected, WP_ICU_Regex_Translator::translate( $pattern, $flags ) ); + } + + public function data_output(): array { + return array( + array( 'abc', '', '/abc/uX' ), + array( 'abc', 'i', '/abc/uXi' ), + array( 'abc', 'ims', '/abc/uXi' ), + array( 'a/b', '', '/a\/b/uX' ), + array( "a\0b", '', '/a\x00b/uX' ), + array( 'a.b', 's', '/a[\s\S]b/uX' ), + array( 'a.b', 'd', '/a[^\n]b/uX' ), + array( '^a$', 'md', '/(?assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '(?:(?s).)a' ), "\na" ) ); + $this->assertSame( 0, preg_match( WP_ICU_Regex_Translator::translate( '(?:(?s).).' ), "\n\n" ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( 'a\n(?m)^b' ), "a\nb" ) ); + $this->assertSame( 0, preg_match( WP_ICU_Regex_Translator::translate( '(?:(?m)a\n)^b' ), "a\nb" ) ); + } + + public function test_the_match_start_can_be_disabled(): void { + $this->assertSame( '/\Ga/uX', WP_ICU_Regex_Translator::translate( '\Ga' ) ); + $this->assertSame( 0, preg_match( WP_ICU_Regex_Translator::translate( '\Ga', '', true ), 'a' ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '\Ga|b', '', true ), 'ab' ) ); + } + + public function test_unknown_flags_are_rejected(): void { + $this->expectException( DomainException::class ); + WP_ICU_Regex_Translator::translate( 'a', 'x' ); + } + + public function test_a_pattern_that_pcre_cannot_compile_is_rejected(): void { + $this->assertSame( '/' . str_repeat( 'a', 65535 ) . '/uX', WP_ICU_Regex_Translator::translate( str_repeat( 'a', 65535 ) ) ); + $this->expectException( DomainException::class ); + WP_ICU_Regex_Translator::translate( str_repeat( 'a', 65536 ) ); + } + + public function test_alphabetic_classes_work_with_any_pcre_version(): void { + $compiled = WP_ICU_Regex_Translator::translate( '[[:alpha:]]+[[:alnum:]]' ); + $this->assertSame( 1, preg_match( $compiled, 'añ日Ⅷ٣', $match ) ); + $this->assertSame( 'añ日Ⅷ٣', $match[0] ); + } + + public function test_long_subjects_stay_within_pcre_limits(): void { + $subject = str_repeat( "ab \r\n", 200000 ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^.*$', 's' ), $subject ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^(?:\w+\b\W+)*$' ), "ab \r\n" ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^[\w\s]*$' ), $subject ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '\A[^x]*\z' ), $subject ) ); + } + + private function as_cases( array $patterns ): array { + return array_map( + static function ( $pattern ) { + return array( $pattern ); + }, + $patterns + ); + } + + /** + * Wrap each match and its captures in angle brackets, advancing after empty matches as ICU does. + */ + private function replace_matches( string $compiled, string $subject ): string { + preg_match_all( $compiled, '', $empty ); + $group_count = count( array_filter( array_keys( $empty ), 'is_int' ) ) - 1; + + $out = ''; + $copied = 0; + $offset = 0; + $length = strlen( $subject ); + while ( $offset <= $length && 1 === preg_match( $compiled, $subject, $match, PREG_OFFSET_CAPTURE, $offset ) ) { + $start = $match[0][1]; + $end = $start + strlen( $match[0][0] ); + $out .= substr( $subject, $copied, $start - $copied ) . '<' . $match[0][0]; + for ( $i = 1; $i <= $group_count; $i++ ) { + $out .= '|' . ( isset( $match[ $i ] ) && $match[ $i ][1] >= 0 ? $match[ $i ][0] : '' ); + } + $out .= '>'; + $copied = $end; + + // After an empty match, ICU continues one code point later. + $offset = $end; + if ( $end === $start ) { + ++$offset; + while ( $offset < $length && 0x80 === ( ord( $subject[ $offset ] ) & 0xC0 ) ) { + ++$offset; + } + } + } + return $out . substr( $subject, $copied ); + } +} From d6cccb2daab6eef8b47ab1119e479f58cfd0b3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Mon, 23 Nov 2026 18:15:02 +0100 Subject: [PATCH 2/5] Avoid a PCRE bug with a negated set of one character MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When ignoring case, PCRE 10.32 to 10.39 with JIT can match only a part of a character with a negated set of one character whose letter has more than one other case, like "[^s]". On "日", it matched two of the three bytes, so REGEXP_SUBSTR() or REGEXP_REPLACE() could return invalid UTF-8. PHP 7.3 to 8.1 bundle these versions. Repeat the character in such a set. PCRE then compiles a class, which doesn't have the bug. --- .../src/icu/class-wp-icu-regex-translator.php | 6 ++++++ .../tests/icu/WP_ICU_Regex_Translator_Tests.php | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php index 5916bbbdd..e095258ce 100644 --- a/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php +++ b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-translator.php @@ -339,6 +339,12 @@ function ( $parts ) use ( &$previous ) { }, substr( $set, $start, -1 ) ); + + // PCRE 10.32–10.39 can match part of a UTF-8 character with "(?i)[^s]". + // Writing "[^ss]" avoids the bug and excludes the same characters. + if ( 2 === $start && preg_match( '/^(?:\\\\x\{[0-9A-F]+\}|\\\\[^a-zA-Z]|[^\\\\])$/su', $body ) ) { + $body .= $body; + } return substr( $set, 0, $start ) . $body . ']'; } diff --git a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php index 35131cd0e..c7f4e8c8f 100644 --- a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php +++ b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php @@ -842,6 +842,13 @@ public function data_output(): array { ); } + public function test_a_negated_set_of_one_character_matches_whole_characters(): void { + $this->assertSame( '/[^ss]/uXi', WP_ICU_Regex_Translator::translate( '[^s]', 'i' ) ); + $this->assertSame( '<日><本>s<😀>', $this->replace_matches( WP_ICU_Regex_Translator::translate( '[^s]', 'i' ), '日本s😀' ) ); + $this->assertSame( '<“x>ς', $this->replace_matches( WP_ICU_Regex_Translator::translate( '[^σ]{2}', 'i' ), '“xς' ) ); + $this->assertSame( '<日>s', $this->replace_matches( WP_ICU_Regex_Translator::translate( '(?i)[^\x73]' ), '日s' ) ); + } + public function test_inline_flags_end_with_their_group(): void { $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '(?:(?s).)a' ), "\na" ) ); $this->assertSame( 0, preg_match( WP_ICU_Regex_Translator::translate( '(?:(?s).).' ), "\n\n" ) ); From dc37a571536c800732c06e3f6dadff3c6d3525d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Mon, 23 Nov 2026 21:04:44 +0100 Subject: [PATCH 3/5] Prepare the ICU regex translator for the REGEXP functions The REGEXP functions need more from the translator than a text pattern: - Match bytes, for binary strings. Classes and word boundaries are the ones of PCRE, and a line ends at LF, VT, FF, and CR, like in MySQL. - Accept a look-behind only when it holds characters, sets, and "|". Older PCRE versions reject other look-behinds, so the same patterns now work with every version. - Raise WP_ICU_Regex_Exception with the MySQL error number 3690, and name the rejected syntax in the message, like "(?x" or "\10". - Write a NUL byte after a backslash as "\x00". PHP before 8.2 rejects a NUL byte in a pattern. --- .../src/icu/class-wp-icu-regex-exception.php | 9 + .../src/icu/class-wp-icu-regex-translator.php | 355 ++++++++++++------ packages/mysql-on-sqlite/src/load.php | 1 + .../icu/WP_ICU_Regex_Translator_Tests.php | 260 +++++++++++-- 4 files changed, 476 insertions(+), 149 deletions(-) create mode 100644 packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-exception.php diff --git a/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-exception.php b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-exception.php new file mode 100644 index 000000000..c84ff248b --- /dev/null +++ b/packages/mysql-on-sqlite/src/icu/class-wp-icu-regex-exception.php @@ -0,0 +1,9 @@ + '[\n\x0B\f\r]', + '\V' => '[^\n\x0B\f\r]', + ); // PCRE counts "²" as a word character. ICU excludes it. private const WORD = '\p{L}\p{M}\p{Nd}\p{Nl}\p{Pc}\x{200C}\x{200D}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}'; + // The titlecase letters, like "Dž", with their uppercase and lowercase forms. + private const TITLECASE = '\x{1C4}-\x{1CC}\x{1F1}-\x{1F3}\x{1F80}-\x{1FAF}\x{1FB3}\x{1FBC}\x{1FC3}\x{1FCC}\x{1FF3}\x{1FFC}'; + // PCRE class bodies for ICU's POSIX classes. private const POSIX_CLASSES = array( 'alnum' => '\p{Alphabetic}\p{Nd}', @@ -55,26 +67,31 @@ class WP_ICU_Regex_Translator { 'print' => '\p{L}\p{M}\p{N}\p{P}\p{S}\p{Cf}\p{Co}\p{Zs}', 'punct' => '\p{P}', 'space' => '\s', - 'upper' => '\p{Lu}', + 'upper' => '\p{Lu}\x{2160}-\x{216F}\x{24B6}-\x{24CF}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}', 'word' => self::WORD, 'xdigit' => '\p{Nd}A-Fa-f\x{FF21}-\x{FF26}\x{FF41}-\x{FF46}', ); - // Translations for ".", "^", and "$" under the active flags. + // Translations for ".", "^", and "$" under the active flags. The ".*" entries + // restrict a leading ".*" or ".+" to the search offset (\G) or a new line. private const NOT_IN_CRLF = '(?!(?<=\r)\n)'; private const LINES = array( - '.' => '[^' . self::LINE_ENDS . ']', - '.d' => '[^\n]', - '.s' => '[\s\S]', - '.sd' => '[\s\S]', - '^' => '\A', - '^d' => '\A', - '^m' => '(?:\A|(?<=[' . self::LINE_ENDS . '])(?!\z))' . self::NOT_IN_CRLF, - '^md' => '(? '(?=(?:\r\n|[' . self::LINE_ENDS . '])?\z)' . self::NOT_IN_CRLF, - '$d' => '(?=\n?\z)', - '$m' => '(?![^' . self::LINE_ENDS . '])' . self::NOT_IN_CRLF, - '$md' => '(?![^\n])', + '.' => '\V', + '.d' => '[^\n]', + '.s' => '[\s\S]', + '.sd' => '[\s\S]', + '.*' => '(?:\G|(?<=\v))', + '.*d' => '(?:\G|(?<=\n))', + '.*s' => '\G', + '.*sd' => '\G', + '^' => '\A', + '^d' => '\A', + '^m' => '(?:\A|(?<=\v)(?!\z))' . self::NOT_IN_CRLF, + '^md' => '(? '(?=(?:\r\n|\v)?\z)' . self::NOT_IN_CRLF, + '$d' => '(?=\n?\z)', + '$m' => '(?!\V)' . self::NOT_IN_CRLF, + '$md' => '(?![^\n])', ); // Escapes outside of a set, and MySQL 5.7's word boundaries. @@ -83,7 +100,7 @@ class WP_ICU_Regex_Translator { 'b' => '(?(?<=[' . self::WORD . '])(?![' . self::WORD . '])|(?=[' . self::WORD . ']))', 'B' => '(?(?<=[' . self::WORD . '])(?=[' . self::WORD . '])|(?![' . self::WORD . ']))', 'G' => '\G', - 'R' => '(?>\r\n|[' . self::LINE_ENDS . '])', + 'R' => '(?>\r\n|\v)', 'X' => '\X', 'z' => '\z', 'Z' => self::LINES['$'], @@ -98,20 +115,29 @@ class WP_ICU_Regex_Translator { private const SET = '(?!\[:[^:]*:\])\[\^?+\]?+(?:' . self::SET_ITEM . ')*+\]'; private const INTERVAL = '\{\d+(?:,\d*)?\}'; private const QUANTIFIER = '((?:[*+?]|' . self::INTERVAL . ')[+?]?)?'; - private const GROUP = '\((?:\?(?:[:=!>]|<[=!]|<[A-Za-z][A-Za-z0-9]*>|#[^)\\\\]*\)|(?=[imsdu-])([imsdu]*)-?([imsdu]*)([:)])))?'; - private const BRACE = '(\}|(?!' . self::INTERVAL . ')\{)'; - private const TOKEN = '/(?:[^\\\\\[(){}|^$.*+?\/\x00]++|' . self::QUOTE . '(?:\\\\E|\z)|' . self::ESCAPE . '|' . self::POSIX . '|' . self::SET . '|[.)\/\x00])' . self::QUANTIFIER . '|' . self::GROUP . '|' . self::BRACE . '|\[\[:[<>]:\]\]|[\s\S]/'; + private const GROUP = '\((?:(?!\?)|\?(?:[:=!>]|<[A-Za-z][A-Za-z0-9]*>|#[^)\\\\]*\)|(?=[imsdu-])([imsdu]*)-?([imsdu]*)([:)])))'; + private const BRACE = '\}|(?!' . self::INTERVAL . ')\{'; + + // Match the whole lookbehind here so each alternative has a fixed length on older PCRE versions. + private const LOOK_BEHIND = '\(\?<[=!](?:' . self::SET . '|(?!\\\\[AbBGkRXzZ1-9])' . self::ESCAPE . '|[^\\\\\[(){}^$.*+?]++|\.)*+\)'; + + // Catch unrecognized syntax so the error can name the offending token. + private const OTHER = '\\\\(?:Q\\\\E|\d+)?|\(\?(?:<[=!]|\w+|[^)])?|[\s\S]'; + private const TOKEN = '/(?:[^\\\\\[(){}|^$.*+?\/\x00]++|' . self::QUOTE . '(?:\\\\E|\z)|' . self::ESCAPE . '|' . self::POSIX . '|' . self::SET . '|[.)\/\x00])' . self::QUANTIFIER . '|' . self::LOOK_BEHIND . '|' . self::GROUP . '|' . self::BRACE . '|\[\[:[<>]:\]\]|[|^$]|(' . self::OTHER . ')/'; // Capture groups in TOKEN. private const CAPTURE_QUANTIFIER = 1; private const CAPTURE_FLAGS_ON = 2; private const CAPTURE_FLAGS_OFF = 3; private const CAPTURE_FLAG_DELIMITER = 4; - private const CAPTURE_BRACE = 5; + private const CAPTURE_UNSUPPORTED = 5; // Cap the input size before expanding tokens such as word boundaries into longer PCRE patterns. private const MAX_LENGTH = 65535; + // MySQL ER_REGEXP_UNIMPLEMENTED. + private const UNSUPPORTED = 3690; + /** * Active ICU flags. * @@ -120,12 +146,33 @@ class WP_ICU_Regex_Translator { private $flags; /** - * Saved flags and repeatability for each open group. + * Saved flags, repeatability, and start-check count for each open group. * * @var array[] */ private $groups = array(); + /** + * Deferred start checks in NUL placeholder order. + * + * @var string[] + */ + private $starts = array(); + + /** + * Whether the pattern contains a backreference. + * + * @var bool + */ + private $has_backreference = false; + + /** + * Whether a leading .* or .+ can restrict the match start here. + * + * @var bool + */ + private $is_leading = true; + /** * Whether \G in the input pattern must fail. * @@ -133,27 +180,42 @@ class WP_ICU_Regex_Translator { */ private $without_g; + /** + * Whether to match byte by byte. + * + * @var bool + */ + private $bytes; + /** * Translate an ICU regular expression to a PCRE pattern. * * @param string $pattern The ICU regular expression. * @param string $flags ICU flags: i (ignore case), m (multiline), s (dotall), d (Unix lines). * @param bool $without_g Disable \G when starting past the previous match or at a nonzero initial offset. + * @param bool $bytes Match individual bytes using PCRE's byte-mode classes and boundaries. * - * @throws DomainException On unsupported syntax, flags, or a translation limit. + * @throws WP_ICU_Regex_Exception On unsupported syntax, flags, or a translation limit. * @return string A pattern for the preg_*() functions. It can still fail to compile. */ - public static function translate( $pattern, $flags = '', $without_g = false ) { + public static function translate( $pattern, $flags = '', $without_g = false, $bytes = false ) { if ( strlen( $pattern ) > self::MAX_LENGTH || strspn( $flags, 'imsd' ) !== strlen( $flags ) ) { - throw new DomainException( 'Unsupported regular expression length or flags.' ); + throw new WP_ICU_Regex_Exception( 'Unsupported regular expression length or flags.', self::UNSUPPORTED ); } $translator = new self(); $translator->flags = $flags; $translator->without_g = $without_g; + $translator->bytes = $bytes; $translated = self::replace( self::TOKEN, array( $translator, 'translate_token' ), $pattern ); + // A backreference can require a later start within a line: "(.*)-\1" matches "b-b" in "ab-b". + // Drop the deferred checks in that case. + foreach ( $translator->starts as $start ) { + $translated = substr_replace( $translated, $translator->has_backreference ? '' : $start, strpos( $translated, "\0" ), 1 ); + } + // "X" stops PHP 7.3 and 7.4 from reading an unknown property as literal text. - return '/' . $translated . '/uX' . ( false !== strpos( $flags, 'i' ) ? 'i' : '' ); + return '/' . $translated . ( $bytes ? '/X' : '/uX' ) . ( false !== strpos( $flags, 'i' ) ? 'i' : '' ); } /** @@ -166,24 +228,27 @@ private function translate_token( $parts ) { $token = $parts[0]; $quantifier = $parts[ self::CAPTURE_QUANTIFIER ] ?? ''; $item = substr( $token, 0, strlen( $token ) - strlen( $quantifier ) ); + if ( isset( $parts[ self::CAPTURE_UNSUPPORTED ] ) ) { + throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: $token", self::UNSUPPORTED ); + } + $is_leading = $this->is_leading; + $this->is_leading = '|' === $token && ! $this->groups; switch ( $item[0] ) { case '\\': // A position, like "\b", can't be repeated. - if ( isset( $item[1] ) && ( '' === $quantifier || false === strpos( 'AbBGzZ', $item[1] ) ) ) { + if ( '' === $quantifier || false === strpos( 'AbBGzZ', $item[1] ) ) { return $this->translate_escape( substr( $item, 1 ), false ) . $quantifier; } break; case '[': if ( isset( self::ESCAPES[ $item ] ) ) { - return self::ESCAPES[ $item ]; + return $this->bytes ? $item : self::ESCAPES[ $item ]; } elseif ( preg_match( '/^\[:[^:]*:\]$/', $item ) ) { // ICU also accepts a POSIX class on its own, as in "[:digit:]". return $this->translate_property( trim( $item, '[:^]' ), '^' === $item[2], false ) . $quantifier; - } elseif ( isset( $item[1] ) ) { - return $this->translate_set( $item ) . $quantifier; } - break; + return $this->translate_set( $item ) . $quantifier; case '(': $delimiter = $parts[ self::CAPTURE_FLAG_DELIMITER ] ?? ''; if ( '' !== $delimiter ) { @@ -191,93 +256,73 @@ private function translate_token( $parts ) { $old = $this->flags; $this->flags = str_replace( str_split( $parts[ self::CAPTURE_FLAGS_OFF ] . '-' ), '', $old . $parts[ self::CAPTURE_FLAGS_ON ] ); if ( ':' === $delimiter ) { - $this->groups[] = array( $old, true ); + $this->groups[] = array( $old, true, count( $this->starts ) ); } + $this->is_leading = $is_leading; return '(?' . ( false !== strpos( $this->flags, 'i' ) ? 'i' : '-i' ) . $delimiter; - } elseif ( '(?#' === substr( $item, 0, 3 ) ) { - return '(?#)'; + } elseif ( ')' === substr( $item, -1 ) ) { + if ( '#' === $item[2] ) { + return '(?#)'; + } + // LOOK_BEHIND excludes nested groups. Translate its contents with the current flags. + $inside = self::replace( self::TOKEN, array( $this, 'translate_token' ), substr( $item, 4, -1 ) ); + $this->is_leading = false; + return substr( $item, 0, 4 ) . $inside . ')'; } - // A look-around can't be repeated. - $is_look_around = false !== strpbrk( $item, '=!' ); - $this->groups[] = array( $this->flags, ! $is_look_around ); + // A lookahead consumes no text. An atomic group keeps its first match. + // Neither can use a leading ".*" to restrict where the whole pattern starts. + $is_look_ahead = false !== strpbrk( $item, '=!' ); + $this->is_leading = $is_leading && ! $is_look_ahead && '(?>' !== $item; + $this->groups[] = array( $this->flags, ! $is_look_ahead, count( $this->starts ) ); return $item; case ')': if ( $this->groups ) { - list( $this->flags, $is_repeatable ) = array_pop( $this->groups ); + list( $this->flags, $is_repeatable, $start_count ) = array_pop( $this->groups ); + if ( '' !== $quantifier && $is_repeatable ) { + // A repeated group can start again mid-line. Clear its checks but keep the placeholder count. + $this->starts = array_pad( array_slice( $this->starts, 0, $start_count ), count( $this->starts ), '' ); + } if ( '' === $quantifier || $is_repeatable ) { return $token; } } break; case '.': - return $this->line_pattern( '.' ) . $quantifier; + $dot = $this->line_pattern( '.' ); + + // PCRE 10.49's JIT can miss "c?-\V{2}" in "-cba". The equivalent set "[^\v]" works. + if ( '\V' === $dot && 0 === strpos( $quantifier, '{' ) ) { + $dot = '[^\v]'; + } + $dot .= $quantifier; + + // PCRE's leading-dot optimization is lost when "." becomes a class. Without JIT, + // a failed search can scan the rest of the line again from every character. + if ( $is_leading && '' !== $quantifier && false !== strpos( '*+', $quantifier[0] ) ) { + $start = $this->line_pattern( '.*' ); + if ( ! $this->groups ) { + return $start . $dot; + } + $this->starts[] = $start; + return "\0" . $dot; + } + return $dot; case '^': case '$': return $this->line_pattern( $item ); case '{': case '}': - // An interval with nothing to repeat is an error. - if ( '' !== ( $parts[ self::CAPTURE_BRACE ] ?? '' ) ) { - return '\\' . $item; - } - break; + return '\\' . $item; case '/': return '\/' . $quantifier; case "\0": return '\x00' . $quantifier; case '|': return '|'; - case '*': - case '+': - case '?': - break; default: return $token; } - throw new DomainException( "Unsupported regular expression syntax: $token" ); - } - - /** - * Translate an escape. - * - * @param string $escape The escape, without its backslash. - * @param bool $in_set Whether the escape is in a set. - * @return string The PCRE text. - */ - private function translate_escape( $escape, $in_set ) { - $letter = $escape[0]; - $lower = strtolower( $letter ); - $rest = substr( $escape, 1 ); - if ( 'Q' === $letter && '' !== $rest ) { - return preg_quote( preg_replace( '/\\\\E$/', '', $rest ), '/' ); - } elseif ( 'p' === $lower && '' !== $rest ) { - return $this->translate_property( substr( $rest, 1, -1 ), 'P' === $letter, $in_set ); - } elseif ( 'k' === $letter && '' !== $rest && ! $in_set ) { - return '\\' . $escape; - } elseif ( '' !== $rest && 'k' !== $letter ) { - // For \cX, ICU takes the low five bits of X. The tokenizer accepts ASCII X. - if ( 'c' === $letter ) { - $code = ord( $rest ) & 0x1F; - } else { - $code = '0' === $letter ? octdec( $rest ) : hexdec( trim( $rest, '{}' ) ); - } - return sprintf( '\x{%X}', $code ); - } elseif ( ! preg_match( '/^[A-Za-z0-9]/', $letter ) || false !== strpos( 'aefnrt', $letter ) ) { - // Preserve escaped punctuation and shared escapes such as \n. - return '\\' . $letter; - } elseif ( false !== strpos( 'dhsvw', $lower ) ) { - $body = 'w' === $lower ? self::WORD : '\\' . $lower; - return $this->class_body( $body, $lower !== $letter, $in_set ); - } elseif ( ! $in_set ) { - if ( 'G' === $letter && $this->without_g ) { - return '(?!)'; - } elseif ( isset( self::ESCAPES[ $letter ] ) ) { - return self::ESCAPES[ $letter ]; - } elseif ( false !== strpos( '123456789', $letter ) ) { - return '\g{' . $letter . '}'; - } - } - throw new DomainException( "Unsupported regular expression syntax: \\$escape" ); + throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: $token", self::UNSUPPORTED ); } /** @@ -301,6 +346,7 @@ function ( $parts ) use ( &$previous ) { if ( '-' === $item || '&' === $item ) { $previous = $item; if ( '-' === $item && 'character' === $last && null === $next ) { + $previous = 'range'; return '-'; } @@ -313,21 +359,24 @@ function ( $parts ) use ( &$previous ) { $is_ends_class = '-' === $item && isset( $next[1] ) && ( 'character' === $last || '&' === $last ); $is_after_amp = '-' === $item && null === $next && '&' === $last; if ( $is_operator || $is_ends_class || $is_after_amp ) { - throw new DomainException( "Unsupported regular expression syntax: $item in a set" ); + throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: $item in a set", self::UNSUPPORTED ); } return '\\' . $item; } elseif ( '[' === $item[0] ) { $previous = 'set'; return $this->translate_property( trim( $item, '[:^]' ), '^' === $item[2], true ); } + + // In [a-c-e], the first range uses up "c", so the second hyphen is literal. + // In [a-cd-e], "d" can start a new range. + $is_range_end = 'range' === $last && preg_match( '/^(?:\\\\[^Q]|.\z)/s' . ( $this->bytes ? '' : 'u' ), $item ); + $previous = $is_range_end ? 'class' : 'character'; if ( '\\' === $item[0] ) { - $previous = 'character'; if ( preg_match( '/^\\\\(?:[pP]\{|[dDhHsSvVwW]$)/', $item ) ) { $previous = isset( $item[2] ) ? 'set' : 'class'; } return $this->translate_escape( substr( $item, 1 ), true ); } - $previous = 'character'; return strtr( $item, array( @@ -348,6 +397,59 @@ function ( $parts ) use ( &$previous ) { return substr( $set, 0, $start ) . $body . ']'; } + /** + * Translate an escape. + * + * @param string $escape The escape, without its backslash. + * @param bool $in_set Whether the escape is in a set. + * @return string The PCRE text. + */ + private function translate_escape( $escape, $in_set ) { + $letter = $escape[0]; + $lower = strtolower( $letter ); + $rest = substr( $escape, 1 ); + if ( 'Q' === $letter && '' !== $rest ) { + return preg_quote( preg_replace( '/\\\\E$/', '', $rest ), '/' ); + } elseif ( 'p' === $lower && '' !== $rest ) { + return $this->translate_property( substr( $rest, 1, -1 ), 'P' === $letter, $in_set ); + } elseif ( 'k' === $letter && '' !== $rest && ! $in_set ) { + $this->has_backreference = true; + return '\\' . $escape; + } elseif ( '' !== $rest && 'k' !== $letter ) { + // For \cX, ICU takes the low five bits of X. The tokenizer accepts ASCII X. + if ( 'c' === $letter ) { + $code = ord( $rest ) & 0x1F; + } else { + $code = '0' === $letter ? octdec( $rest ) : hexdec( trim( $rest, '{}' ) ); + } + return sprintf( '\x{%X}', $code ); + } elseif ( "\0" === $letter ) { + // PHP before 8.2 rejects a NUL byte in a pattern. + return '\x00'; + } elseif ( ! preg_match( '/^[A-Za-z0-9]/', $letter ) || false !== strpos( 'aefnrt', $letter ) ) { + // Preserve escaped punctuation and shared escapes such as \n. + return '\\' . $letter; + } elseif ( false !== strpos( 'CEFgIiJjKLlMmOoqTYy', $letter ) ) { + // ICU treats these letters literally. Removing the backslash prevents PCRE from interpreting escapes such as \K. + return $letter; + } elseif ( false !== strpos( 'dhsvw', $lower ) ) { + $body = 'w' === $lower && ! $this->bytes ? self::WORD : '\\' . $lower; + return $this->class_body( $body, $lower !== $letter, $in_set ); + } elseif ( ! $in_set ) { + if ( 'G' === $letter && $this->without_g ) { + return '(?!)'; + } elseif ( 'b' === $lower && $this->bytes ) { + return '\\' . $letter; + } elseif ( isset( self::ESCAPES[ $letter ] ) ) { + return $this->with_line_ends( self::ESCAPES[ $letter ] ); + } elseif ( false !== strpos( '123456789', $letter ) ) { + $this->has_backreference = true; + return '\g{' . $letter . '}'; + } + } + throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: \\$escape", self::UNSUPPORTED ); + } + /** * Translate a property name, like "Lu", "Greek", or "alpha". * @@ -358,19 +460,24 @@ function ( $parts ) use ( &$previous ) { */ private function translate_property( $name, $negated, $in_set ) { $key = strtolower( $name ); - if ( false !== strpos( $this->flags, 'i' ) && in_array( $key, array( 'lu', 'll', 'lt', 'upper', 'lower' ), true ) ) { - // Lu, Ll, and Lt expand to all cased letters. - $body = '\p{L&}'; + if ( 'alphabetic' === $key ) { + // Use the same fallback for Alphabetic and the POSIX alpha class on older PCRE versions. + $key = 'alpha'; + } + if ( $this->bytes && isset( self::POSIX_CLASSES[ $key ] ) ) { + $body = '[:' . $key . ':]'; + } elseif ( false !== strpos( $this->flags, 'i' ) && in_array( $key, array( 'lu', 'll', 'lt', 'upper', 'lower' ), true ) ) { + // Lu and Ll expand to all cased letters. Lt needs only titlecase letters and their case variants. + $body = 'lt' === $key && ! $this->bytes ? self::TITLECASE : '\p{L&}'; } elseif ( isset( self::POSIX_CLASSES[ $key ] ) ) { $body = self::POSIX_CLASSES[ $key ]; - } elseif ( preg_match( '/^[a-z]{1,2}$/', $key ) ) { - // A general category. PCRE rejects the ones that it doesn't know. + } elseif ( preg_match( '/^(?:c[cfnos]?|l[clmotu]?|m[cen]?|n[dlo]?|p[cdefios]?|s[ckmo]?|z[lps]?)$/D', $key ) ) { $body = '\p{' . ( 'lc' === $key ? 'L&' : ucfirst( $key ) ) . '}'; - } elseif ( preg_match( '/^[A-Z][a-z]{2,}(?:_[A-Z][a-z]+)*$/', $name ) && ! in_array( $name, array( 'Any', 'Xan', 'Xps', 'Xsp', 'Xuc', 'Xwd' ), true ) ) { + } elseif ( preg_match( '/^[A-Z][a-z]+(?:_[A-Z][a-z]+)*$/D', $name ) && ! in_array( $name, array( 'Any', 'Xan', 'Xps', 'Xsp', 'Xuc', 'Xwd' ), true ) ) { // From PCRE 10.40, a bare script name can mean Script_Extensions. Request Script explicitly. $body = '\p{' . ( self::has_pcre_10_40() ? 'sc:' : '' ) . $name . '}'; } else { - throw new DomainException( "Unsupported regular expression property: $name" ); + throw new WP_ICU_Regex_Exception( "Unsupported regular expression property: $name", self::UNSUPPORTED ); } return $this->class_body( $body, $negated, $in_set ); } @@ -392,19 +499,21 @@ private function class_body( $body, $negated, $in_set ) { return '[' . ( $negated ? '^' : '' ) . $body . ']'; } elseif ( ! $negated ) { return $body; - } elseif ( ! preg_match( '/^\\\\(?:[dhsv]|p\{(?!Alphabetic)[^}]*\})$/', $body ) ) { + } elseif ( '[' === $body[0] ) { + return '[:^' . substr( $body, 2 ); + } elseif ( ! preg_match( '/^\\\\(?:[dhsvw]|p\{(?!Alphabetic)[^}]*\})$/', $body ) ) { // Inside a set, PCRE can negate only a single class item. Alphabetic expands // to several items on older versions, so reject its negation here on all versions. - throw new DomainException( 'Unsupported regular expression syntax: a negated class in a set' ); + throw new WP_ICU_Regex_Exception( 'Unsupported regular expression syntax: a negated class in a set', self::UNSUPPORTED ); } $body[1] = strtoupper( $body[1] ); return $body; } /** - * Select a line pattern for the active flags. + * Select a line pattern for the active flags and byte mode. * - * @param string $token A dot or a line anchor. + * @param string $token A dot, a line anchor, or ".*" for a leading-dot start check. * @return string The PCRE fragment. */ private function line_pattern( $token ) { @@ -416,7 +525,17 @@ private function line_pattern( $token ) { if ( false !== strpos( $this->flags, 'd' ) ) { $key .= 'd'; } - return self::LINES[ $key ]; + return $this->with_line_ends( self::LINES[ $key ] ); + } + + /** + * Adapt a generated line-ending expression for byte mode. + * + * @param string $fragment The PCRE text of ".", "^", "$", or an escape. + * @return string The PCRE text for the current mode. + */ + private function with_line_ends( $fragment ) { + return $this->bytes ? strtr( $fragment, self::BYTE_LINE_ENDS ) : $fragment; } /** @@ -431,7 +550,7 @@ private function line_pattern( $token ) { private static function replace( $regex, $callback, $text ) { $replaced = preg_replace_callback( $regex, $callback, $text ); if ( null === $replaced ) { - throw new DomainException( 'Unsupported regular expression: it is too complex.' ); + throw new WP_ICU_Regex_Exception( 'Unsupported regular expression: it is too complex.', self::UNSUPPORTED ); } return $replaced; } diff --git a/packages/mysql-on-sqlite/src/load.php b/packages/mysql-on-sqlite/src/load.php index d05f12054..93f6cd4c3 100644 --- a/packages/mysql-on-sqlite/src/load.php +++ b/packages/mysql-on-sqlite/src/load.php @@ -19,6 +19,7 @@ require_once __DIR__ . '/mysql/class-wp-mysql-lexer.php'; require_once __DIR__ . '/mysql/class-wp-mysql-parser.php'; +require_once __DIR__ . '/icu/class-wp-icu-regex-exception.php'; require_once __DIR__ . '/icu/class-wp-icu-regex-translator.php'; require_once __DIR__ . '/sqlite/class-wp-sqlite-connection.php'; require_once __DIR__ . '/sqlite/class-wp-sqlite-configurator.php'; diff --git a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php index c7f4e8c8f..06d2c2749 100644 --- a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php +++ b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php @@ -58,6 +58,20 @@ public function data_matches(): array { array( '\\*', '', '*', '<*>' ), array( '\\\\', '', '\\', '<\\>' ), array( '\\/', '', '/', '' ), + // ICU treats these escaped letters literally, including PCRE escapes such as \K. + array( '\\y+', '', 'yy', '' ), + array( 'a\\Kb', '', 'aKb ab', ' ab' ), + array( '(?<=\\Ka)b', '', 'Kab ab', 'Ka ab' ), + array( '\\K', 'i', 'kK', '' ), + array( '(a)\\g1', '', 'aa ag1', 'aa ' ), + array( '(a)\\g{1}', '', 'aa ag', 'aa ' ), + array( '(a)\\g<1>', '', 'ag<1>', '|a>' ), + array( '\\o{3}', '', 'ooo', '' ), + array( 'a\\Eb', '', 'aEb', '' ), + array( 'a\\Q.\\E\\Eb', '', 'a.Eb', '' ), + array( '[a-\\y]+', '', 'ayz', 'z' ), + array( '[^\\y]', '', 'yz', 'y' ), + array( '\\C\\E\\F\\g\\I\\i\\J\\j\\K\\L\\l\\M\\m\\O\\o\\q\\T\\Y\\y', '', 'CEFgIiJjKLlMmOoqTYy', '' ), // Quantifiers. array( 'a*', '', 'aab', '<>b<>' ), array( 'a+', '', 'aab', 'b' ), @@ -144,6 +158,14 @@ public function data_matches(): array { array( '[-a]', '', '-a', '<->' ), array( '[a-]', '', '-a', '<->' ), array( '[a-c-e]', '', 'be-d', '<->d' ), + array( '[a-c-e-g]', '', 'bdefg-', 'd<->' ), + array( '[a-c-\\d]', '', 'b-1e', '<-><1>e' ), + array( '[a-c0-9-\\s]', '', 'b5- e', '<5><->< >e' ), + array( '[^a-c-\\d]', '', 'b-1e', 'b-1' ), + array( '[а-я-\\w]', '', 'я-_!', '<я><-><_>!' ), + array( '[\\x41-\\x43-\\p{Nd}]', '', 'B-1D', '<-><1>D' ), + array( '[a-c-[:digit:]]', '', 'b-1e', '<-><1>e' ), + array( '[a-c&\\d]', '', 'b&1e', '<&><1>e' ), array( '[\\w-z]', '', '-z.', '<->.' ), array( '[\\d-a]', '', '1-ab', '<1><->b' ), array( '[\\p{Lu}-z]', '', 'A-z', '<->' ), @@ -188,6 +210,9 @@ public function data_matches(): array { array( '[[:punct:]]', '', 'a.+', 'a<.>+' ), array( '[[:space:]]', '', "a \n", "a< ><\n>" ), array( '[[:upper:]]', '', 'aA', 'a' ), + array( '[[:upper:]]', '', 'ⅧⅷⒶⓐ🄰', '<Ⅷ>ⅷ<Ⓐ>ⓐ<🄰>' ), + array( '[:^upper:]', '', 'aAⅧ', 'AⅧ' ), + array( '\\p{upper}', '', 'aAⅧ', 'a<Ⅷ>' ), array( '[[:upper:]]', 'i', 'aA1', '1' ), array( '[[:lower:]]', 'i', 'aA1', '1' ), array( '[[:word:]]', '', 'a_-', '<_>-' ), @@ -202,16 +227,26 @@ public function data_matches(): array { array( '\\p{lu}', '', 'aA', 'a' ), array( '\\p{ASCII}', '', 'aé', 'é' ), array( '\\p{word}', '', 'a-', '-' ), + array( '\\p{Alphabetic}', '', 'aⒶ1', '<Ⓐ>1' ), + array( '\\P{Alphabetic}', '', 'aⒶ1', 'aⒶ<1>' ), + array( '[\\p{Alphabetic}_]', '', 'a_1', '<_>1' ), array( '\\p{Greek}', '', 'aα', 'a<α>' ), array( '\\P{Greek}', '', 'aα', 'α' ), array( '\\p{Han}', '', '日。', '<日>。' ), array( '\\p{Old_Italic}', '', '𐌀a', '<𐌀>a' ), + array( '\\p{Yi}', '', 'ꀀ、', '<ꀀ>、' ), + array( '\\p{LC}', '', 'aA1', '1' ), + array( '\\p{Cn}', '', "a\u{FFFF}", "a<\u{FFFF}>" ), array( '\\p{Lu}', 'i', 'aA1', '1' ), array( '\\P{Lu}', 'i', 'aA1', 'aA<1>' ), array( '\\p{Ll}', 'i', 'aA1', '1' ), array( '(?i)\\p{Lu}', '', 'aA1', '1' ), array( '(?i:\\p{Lu})\\p{Lu}', '', 'aa', 'aa' ), array( '(?i:\\p{Lu})\\p{Lu}', '', 'aA', '' ), + array( '\\p{Lt}', '', 'DždžDŽa', '<Dž>džDŽa' ), + array( '\\p{Lt}', 'i', 'DždžDŽaAᾈᾀ', '<Dž><dž><DŽ>aA<ᾈ><ᾀ>' ), + array( '\\P{Lt}', 'i', 'DždžaA', 'Dždž' ), + array( '[\\p{Lt}x]', 'i', 'džXa', '<dž>a' ), array( '(?-i)\\p{Lu}', 'i', 'aA', 'a' ), array( '\\p{Nd}', '', 'a٣', 'a<٣>' ), array( '\\p{Zs}', '', "a\u{A0}", "a<\u{A0}>" ), @@ -328,7 +363,6 @@ public function data_first_match(): array { array( 'a?+a', 'a', null ), array( 'a(?=b)', 'ab', 'a' ), array( 'a(?!b)', 'ac', 'a' ), - array( '(?<=ab{2})c', 'abbc', 'c' ), array( '(?a+)b\k', 'aaabaaa', 'aaabaaa' ), array( '(a)(b)\2\1', 'abba', 'abba' ), @@ -388,8 +422,6 @@ public function data_first_match(): array { array( '[^]a]+', 'bc', 'bc' ), array( '[-a&]+', '-a&', '-a&' ), array( '(?dm)\n^', "\n", "\n" ), - array( '(?<=abc{2})d', 'abccd', 'd' ), - array( '(?<=(?:a|b){2})c', 'abc', 'c' ), array( '\A[a\D]+\z', str_repeat( 'a', 64 ) . '1', null ), array( '[abcdefghijk-z]+', 'ijxyz', 'ijxyz' ), array( '[:digit:]+', '١٢', '١٢' ), @@ -436,7 +468,7 @@ public function test_known_differences( string $pattern, string $flags, string $ */ public function data_known_differences(): array { return array( - array( '\\p{Lt}', 'i', 'Dždža', '<Dž><dž>a', '<Dž><dž>' ), + array( '\\p{Greek}', 'i', 'µμ', '<µ><μ>', 'µ<μ>' ), array( '\\s', '', "\u{180E}", "\u{180E}", "<\u{180E}>" ), array( '\\S', '', "a \u{180E}", " <\u{180E}>", " \u{180E}" ), array( '\\h', '', "a \t\n\u{A0}\u{180E}", "a< ><\t>\n<\u{A0}>\u{180E}", "a< ><\t>\n<\u{A0}><\u{180E}>" ), @@ -474,19 +506,15 @@ public function data_known_differences(): array { * @dataProvider data_unsupported_syntax */ public function test_unsupported_syntax( string $pattern ): void { - $this->expectException( DomainException::class ); + $this->expectException( WP_ICU_Regex_Exception::class ); + $this->expectExceptionCode( 3690 ); WP_ICU_Regex_Translator::translate( $pattern ); } public function data_unsupported_syntax(): array { return $this->as_cases( array( - '\\y', - '\\K', - '\\C', - '\\g{1}', '\\Q\\E', - 'a\\Eb', '^*a', '$*a', '^+a', @@ -512,7 +540,6 @@ public function data_unsupported_syntax(): array { '(?x)( ?:a)', '[\\b]', '[\\1]', - '[\\y]', '[a-\\p]', '[a[bc]d]', '[a[^b]]', @@ -551,6 +578,8 @@ public function data_unsupported_syntax(): array { '[a][&-c]', '(?i)[[a-c]--[B]]', '[[:^alpha:]]', + '[[:^upper:]]', + '[\\P{Alphabetic}]', '[:a\\x41:]', '\\p{uppercase letter}', '\\p{UPPERCASE-LETTER}', @@ -566,10 +595,11 @@ public function data_unsupported_syntax(): array { '\\p{Script=Greek}', '\\p{sc=Han}', '\\p{old italic}', + '\\p{RI}', + '\\p{di}', '^*', + '(?<=ab{2})c', '(a)\12', - '\j\K\C', - '\E', 'a\Q\E+', '(?x)\Q #[]() \E', '(?x)[\Q ^ \E]', @@ -605,6 +635,8 @@ public function data_unsupported_syntax(): array { '[[a-z]&[bc]\d]', '[[a-z]&[bc]d]', '[[a-z]-[bc]&\p{L}]', + '(?<=abc{2})d', + '(?<=(?:a|b){2})c', '[ab--bc]', '[a--b&&b]', '[[a][b][c]]+', @@ -619,6 +651,20 @@ public function data_unsupported_syntax(): array { '\p{General_Category=Decimal_Number}+', '\p{gC=lU}+', '\p{upper-case_letter}+', + + // Lookbehinds outside the fixed-length subset. + '(?<=a?)b', + '(?<=a{2})b', + '(?<=a{1,2})b', + '(?expectException( DomainException::class ); + $this->expectException( WP_ICU_Regex_Exception::class ); + $this->expectExceptionCode( 3690 ); WP_ICU_Regex_Translator::translate( $pattern ); } @@ -679,10 +726,6 @@ public function data_pcre_syntax(): array { '(?a)(?P=n)', '(?a)\\k\'n\'', '(?a)\\k{n}', - '(a)\\g1', - '(a)\\g{1}', - '(a)\\g{-1}', - '(a)\\g<1>', '(?U)a', '(?J)a', '(?n)a', @@ -694,13 +737,6 @@ public function data_pcre_syntax(): array { '\\N', 'a\\N+', '\\N{U+41}', - '\\K', - 'a\\Kb', - '(?<=\\Ka)', - '\\C', - '\\o{101}', - '\\E', - 'a\\Eb', '\\pL', '\\PL', '\\p{L&}', @@ -735,7 +771,7 @@ public function data_pcre_syntax(): array { public function test_invalid_patterns_do_not_compile( string $pattern ): void { try { $compiled = WP_ICU_Regex_Translator::translate( $pattern ); - } catch ( DomainException $e ) { + } catch ( WP_ICU_Regex_Exception $e ) { $this->addToAssertionCount( 1 ); return; } @@ -779,12 +815,17 @@ public function data_invalid_patterns(): array { 'a\\', '[z-a]', '[a-\\d]', + '[a-cd-\\d]', + '[a-c&-\\d]', '[--a]', '[a--]', '[&&a]', '[a&&]', '\\p{Nope}', '\\p{Greekish}', + '\\p{Xx}', + "\\p{Lu\n}", + "\\p{Greek\n}", '\\p{L', '\\p', '(?x)(?y)', @@ -820,6 +861,7 @@ public function data_output(): array { array( 'abc', 'ims', '/abc/uXi' ), array( 'a/b', '', '/a\/b/uX' ), array( "a\0b", '', '/a\x00b/uX' ), + array( "a\\\0b[\\\0]", '', '/a\x00b[\x00]/uX' ), array( 'a.b', 's', '/a[\s\S]b/uX' ), array( 'a.b', 'd', '/a[^\n]b/uX' ), array( '^a$', 'md', '/(?.+))a', 's', '/((?\G[\s\S]+))a/uX' ), + array( '((?s).*)a', 'd', '/((?-i)\G[\s\S]*)a/uX' ), + array( '(.*a)+|(.*)?b|((.*)c){2}', 'd', '/([^\n]*a)+|([^\n]*)?b|(([^\n]*)c){2}/uX' ), + array( "(\0)|(.*a)|((.*b)c){2}|(?s:.+d)", 'd', '/(\x00)|((?:\G|(?<=\n))[^\n]*a)|(([^\n]*b)c){2}|(?-i:\G[\s\S]+d)/uX' ), + array( '(.*a)|(.+b)\2', 's', '/([\s\S]*a)|([\s\S]+b)\g{2}/uX' ), + array( '(?=.*a)b|(?>.*a)b', 'd', '/(?=[^\n]*a)b|(?>[^\n]*a)b/uX' ), + array( '(.*)a\1', 'd', '/([^\n]*)a\g{1}/uX' ), + array( '(?.*)a\k', 'd', '/(?[^\n]*)a\k/uX' ), + array( '.*(a)\1', 'd', '/(?:\G|(?<=\n))[^\n]*(a)\g{1}/uX' ), + ); + } + + /** + * @dataProvider data_bytes + */ + public function test_bytes( string $pattern, string $flags, string $subject, ?string $expected ): void { + $found = preg_match( WP_ICU_Regex_Translator::translate( $pattern, $flags, false, true ), $subject, $match ); + $this->assertSame( $expected, 1 === $found ? $match[0] : null ); + } + + /** + * Byte-mode line endings are LF, VT, FF, and CR. A byte with value 0x85 is ordinary data. + */ + public function data_bytes(): array { + return array( + array( '.', '', "\xC4\x85", "\xC4" ), + array( '^..$', '', "\xC4\x85", "\xC4\x85" ), + array( '^a.$', '', "a\x85", "a\x85" ), + array( '^a.$', '', "a\x0B", null ), + array( '^a.$', '', "a\x0C", null ), + array( '^a.$', '', "a\r", null ), + array( '^a.$', '', "a\n", null ), + array( 'a.', 's', "a\n", "a\n" ), + array( 'a.', 'd', "a\r", "a\r" ), + array( 'a$', '', "a\x85", null ), + array( 'a$', '', "a\x0B", 'a' ), + array( 'a$', '', "a\r\n", 'a' ), + array( 'a$', '', "a\n\n", null ), + array( 'a$', 'd', "a\r", null ), + array( 'a$', 'm', "a\x0Cb", 'a' ), + array( '^a', 'm', "\x85a", null ), + array( '^a', 'm', "\x0Ca", 'a' ), + array( 'a\Z', '', "a\r\n", 'a' ), + array( 'a\Z', '', "a\x85", null ), + array( '\R', '', "\x85", null ), + array( '\R', '', "\x0B", "\x0B" ), + array( '\R', '', "\r\n", "\r\n" ), + array( 'a', '', 'A', null ), + array( 'a', 'i', 'A', 'A' ), + array( '\w+', '', "-ab_1\xC3\xA9", 'ab_1' ), + array( '\W', '', 'a-', '-' ), + array( '\d+', '', 'a12', '12' ), + array( '\D', '', '1a', 'a' ), + array( '\s\S', '', 'a b', ' b' ), + array( '\h\v', '', "a\t\n", "\t\n" ), + array( '[\w-]+', '', 'a-b c', 'a-b' ), + array( '[^\w]', '', 'a-', '-' ), + array( '[\W]', '', 'a-', '-' ), + array( '[^\d\s]', '', '1 o', 'o' ), + array( '[[:alpha:]]+', '', "1ab\xE9", 'ab' ), + array( '[[:^alpha:]]', '', 'a1', '1' ), + array( '[^[:alpha:]]', '', 'a1', '1' ), + array( '[:alpha:]+', '', '1ab2', 'ab' ), + array( '\p{alpha}', '', '1a', 'a' ), + array( '\p{Alphabetic}', '', '1a', 'a' ), + array( '[[:upper:]]', '', 'aB', 'B' ), + array( '[[:upper:]]', 'i', 'aB', 'a' ), + array( '[[:punct:][:digit:]]+', '', 'a!.1b', '!.1' ), + array( '[[:word:]]+', '', '-a_1', 'a_1' ), + array( '[[:xdigit:]]+', '', 'g1A', '1A' ), + array( 'a\b', '', 'a b', 'a' ), + array( 'a\b', '', 'ab', null ), + array( 'a\B', '', 'ab', 'a' ), + array( '[[:<:]]b[[:>:]]', '', 'ab b', 'b' ), + array( '\xE9', '', "\xE9", "\xE9" ), + array( '\x{E9}', '', "\xE9", "\xE9" ), + array( "[\x80-\xFF]", '', "a\xE9", "\xE9" ), + array( "[^\xE9]", 'i', "\xE9a", 'a' ), + array( "(?<=\xC3)\xA9", '', "\xC3\xA9", "\xA9" ), + array( '\Qa.b\E', '', 'a.b', 'a.b' ), + array( "a/\0b", '', "a/\0b", "a/\0b" ), + ); + } + + public function test_bytes_use_the_classes_of_pcre(): void { + $this->assertSame( + '/a[^\n\x0B\f\r][\w][^\d][[:alpha:][:^digit:]\S]\b[[:<:]]/Xi', + WP_ICU_Regex_Translator::translate( 'a.\w\D[[:alpha:][:^digit:]\S]\b[[:<:]]', 'i', false, true ) ); } + public function test_a_code_point_above_a_byte_does_not_compile_for_bytes(): void { + set_error_handler( static function () {} ); + try { + $result = preg_match( WP_ICU_Regex_Translator::translate( '\x{100}', '', false, true ), '' ); + } finally { + restore_error_handler(); + } + $this->assertFalse( $result ); + } + public function test_a_negated_set_of_one_character_matches_whole_characters(): void { $this->assertSame( '/[^ss]/uXi', WP_ICU_Regex_Translator::translate( '[^s]', 'i' ) ); $this->assertSame( '<日><本>s<😀>', $this->replace_matches( WP_ICU_Regex_Translator::translate( '[^s]', 'i' ), '日本s😀' ) ); @@ -862,14 +1024,40 @@ public function test_the_match_start_can_be_disabled(): void { $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '\Ga|b', '', true ), 'ab' ) ); } + public function test_a_leading_dot_star_matches_like_any_other(): void { + $this->assertSame( "\n", $this->replace_matches( WP_ICU_Regex_Translator::translate( '.*b' ), "ab\ncb" ) ); + $this->assertSame( "\nb\n", $this->replace_matches( WP_ICU_Regex_Translator::translate( '.+b' ), "ab\nb\ncb" ) ); + $this->assertSame( "", $this->replace_matches( WP_ICU_Regex_Translator::translate( '.*b', 's' ), "ab\r\ncb" ) ); + $this->assertSame( "", $this->replace_matches( WP_ICU_Regex_Translator::translate( '.*b', 'd' ), "ab\rcb" ) ); + $this->assertSame( "<>\u{2028}<>", $this->replace_matches( WP_ICU_Regex_Translator::translate( '.*' ), "a\u{2028}b" ) ); + $this->assertSame( 'b', $this->replace_matches( WP_ICU_Regex_Translator::translate( 'a|.*c' ), 'ab' ) ); + + $this->assertSame( "\n", $this->replace_matches( WP_ICU_Regex_Translator::translate( '(?:.*)b' ), "ab\ncb" ) ); + $this->assertSame( "\nb\n", $this->replace_matches( WP_ICU_Regex_Translator::translate( '(?i:(?:.+)b)' ), "ab\nb\ncb" ) ); + $this->assertSame( 'a', $this->replace_matches( WP_ICU_Regex_Translator::translate( '(.*)-\1' ), 'ab-b' ) ); + $this->assertSame( '', $this->replace_matches( WP_ICU_Regex_Translator::translate( '(.*a){2}' ), 'xaya' ) ); + $this->assertSame( 'a', $this->replace_matches( WP_ICU_Regex_Translator::translate( '(?>.*?a)b' ), 'aab' ) ); + $this->assertSame( 'x', $this->replace_matches( WP_ICU_Regex_Translator::translate( '(?=.*b)b' ), 'xb' ) ); + + // A search can start in the middle of a line. + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '.*c' ), "abc\nabc", $match, 0, 1 ) ); + $this->assertSame( 'bc', $match[0] ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '.*c', 's' ), "abc\nabc", $match, 0, 1 ) ); + $this->assertSame( "bc\nabc", $match[0] ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '(.*)c' ), "abc\nabc", $match, 0, 1 ) ); + $this->assertSame( 'bc', $match[0] ); + + $this->assertSame( '/(?:\G|(?<=[\n\x0B\f\r]))[^\n\x0B\f\r]*a/X', WP_ICU_Regex_Translator::translate( '.*a', '', false, true ) ); + } + public function test_unknown_flags_are_rejected(): void { - $this->expectException( DomainException::class ); + $this->expectException( WP_ICU_Regex_Exception::class ); WP_ICU_Regex_Translator::translate( 'a', 'x' ); } - public function test_a_pattern_that_pcre_cannot_compile_is_rejected(): void { + public function test_a_pattern_above_the_length_limit_is_rejected(): void { $this->assertSame( '/' . str_repeat( 'a', 65535 ) . '/uX', WP_ICU_Regex_Translator::translate( str_repeat( 'a', 65535 ) ) ); - $this->expectException( DomainException::class ); + $this->expectException( WP_ICU_Regex_Exception::class ); WP_ICU_Regex_Translator::translate( str_repeat( 'a', 65536 ) ); } @@ -882,11 +1070,21 @@ public function test_alphabetic_classes_work_with_any_pcre_version(): void { public function test_long_subjects_stay_within_pcre_limits(): void { $subject = str_repeat( "ab \r\n", 200000 ); $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^.*$', 's' ), $subject ) ); - $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^(?:\w+\b\W+)*$' ), "ab \r\n" ) ); $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '^[\w\s]*$' ), $subject ) ); $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( '\A[^x]*\z' ), $subject ) ); } + public function test_a_dot_with_a_count_matches_after_an_optional_character(): void { + $this->assertSame( '<-cb>a', $this->replace_matches( WP_ICU_Regex_Translator::translate( 'c?-.{2}' ), '-cba' ) ); + $this->assertSame( '<-cba>', $this->replace_matches( WP_ICU_Regex_Translator::translate( 'c?-.{2,}' ), '-cba' ) ); + } + + public function test_a_pattern_with_many_dots_compiles(): void { + // Expanding each dot into a large set can push a long alternation over PCRE's compiled pattern size limit. + $pattern = implode( '|', array_fill( 0, 3000, '10.0.0.1' ) ); + $this->assertSame( 1, preg_match( WP_ICU_Regex_Translator::translate( $pattern ), '10-0-0-1' ) ); + } + private function as_cases( array $patterns ): array { return array_map( static function ( $pattern ) { From 7730e0337055937d30d362dbfd22b7b708a71d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Mon, 23 Nov 2026 21:05:59 +0100 Subject: [PATCH 4/5] Translate REGEXP patterns from ICU to PCRE MySQL uses ICU for regular expressions, and the REGEXP functions passed a pattern to PCRE almost as it was. PCRE reads some of the syntax in another way, so a query could return a wrong result without an error. The functions now use WP_ICU_Regex_Translator. A pattern either gets a correct translation, or it raises an error that names its syntax. This replaces the pattern escaping and the "(*ANY)" line end setting, and fixes these results: - "[^a-z]cat" didn't match "dog\r\ncat". - "[^s]" matched a part of a character on PHP 7.3 to 8.1. - A code point escape, "\w" with marks, and the POSIX classes now work like in ICU. Regular expression errors now carry their MySQL error number, like 3685 for an empty pattern and 3690 for syntax that isn't supported. In the REGEXP suites, "unsupported.json" lists the cases with syntax that isn't supported. They must raise error 3690, so they can't return a wrong result. The known failures of each function shrink to about 60 cases, each with its cause, and they depend on the PCRE version in three places only. --- .../src/sqlite/class-wp-mysql-on-sqlite.php | 7 + ...s-wp-sqlite-pdo-user-defined-functions.php | 191 +--- .../tests/WP_MySQL_On_SQLite_Tests.php | 249 +++-- .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 949 +---------------- .../WP_MySQL_On_SQLite_Regexp_Like_Tests.php | 909 +--------------- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 974 +----------------- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 949 +---------------- .../WP_MySQL_On_SQLite_Regexp_Test_Case.php | 41 +- .../tests/regexp/data/unsupported.json | 119 +++ 9 files changed, 443 insertions(+), 3945 deletions(-) create mode 100644 packages/mysql-on-sqlite/tests/regexp/data/unsupported.json diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php index 1e9053e18..23675f387 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php @@ -1231,6 +1231,13 @@ public function query( string $query, ?int $fetch_mode = null, ...$fetch_mode_ar } if ( $e instanceof WP_MySQL_On_SQLite_Exception ) { $driver_exception = $e; + } elseif ( $e instanceof WP_ICU_Regex_Exception ) { + $driver_exception = $this->new_driver_exception( + sprintf( 'SQLSTATE[HY000]: General error: %d %s', $e->getCode(), $e->getMessage() ), + 'HY000', + $e, + array( 'HY000', $e->getCode(), $e->getMessage() ) + ); } elseif ( $e instanceof PDOException ) { $driver_exception = $this->convert_sqlite_exception( $e ); } else { 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..dcd9a07a6 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 @@ -1232,24 +1232,13 @@ private function regexp_check_match_type( $function_name, $match_type ) { } /** - * Compile a MySQL-style regex into a PCRE pattern string. - * - * Translates MySQL match_type flags (c/i/m/n/u) to PCRE modifiers. The u - * (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: - * - * - Text matching ignores case unless the `c` flag is passed, as the column - * collation isn't known here. - * - PCRE doesn't match "ß" with "ss" when ignoring case, `$` also matches - * between CR and LF, and `(?P...)` is valid. - * - `\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 - * sensitivity, and whether positions count bytes, can differ between rows. + * Compile and cache a MySQL regex. WP_ICU_Regex_Translator documents the supported syntax. + * + * The SQL functions also have these limits: + * + * - Column collations are unavailable here, so text matching ignores case by default. + * - Invalid UTF-8 triggers byte matching, which defaults to case-sensitive. Other + * binary strings can match as text, so positions may count characters or bytes. * - SQLite converts numbers to text in its own format, so `20e0` reads "20.0" * (MySQL: "20"), and `0.000001` reads "1.0e-06". * - `pos`, `occurrence`, and `return_option` use PHP's integer conversion, so @@ -1260,17 +1249,16 @@ private function regexp_check_match_type( $function_name, $match_type ) { * @param string $pattern The MySQL regex pattern. * @param string $match_type MySQL match_type flag string. * @param bool $binary_mode Whether to match bytes instead of UTF-8 characters. - * @param bool $without_g Whether "\G" never matches, for a search that doesn't - * start where the previous match ended. + * @param bool $without_g Disable \G when the search starts past the previous match or at a nonzero initial offset. * - * @throws Exception If the pattern is empty or invalid. + * @throws WP_ICU_Regex_Exception If the pattern is empty, invalid, unsupported, or exceeds a translation limit. * @return string PCRE-ready pattern with delimiter and modifiers. */ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $without_g = false ) { $match_type = (string) $match_type; $pattern = (string) $pattern; if ( '' === $pattern ) { - throw new Exception( 'Illegal argument to a regular expression.' ); + throw new WP_ICU_Regex_Exception( 'Illegal argument to a regular expression.', 3685 ); } // Without "\G" in the pattern, both versions are the same. @@ -1280,61 +1268,13 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w return $this->regexp_cache[ $cache_key ]; } - $case_sensitive = false; - $multiline = false; - $dotall = false; - $unix_lines = false; - $len = strlen( $match_type ); - for ( $i = 0; $i < $len; $i++ ) { - $flag = $match_type[ $i ]; - if ( 'c' === $flag ) { - $case_sensitive = true; - } elseif ( 'i' === $flag ) { - $case_sensitive = false; - } elseif ( 'm' === $flag ) { - $multiline = true; - } elseif ( 'n' === $flag ) { - $dotall = true; - } elseif ( 'u' === $flag ) { - $unix_lines = true; - } - } - - /* - * 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. - */ - $modifiers = $binary_mode ? 'X' : 'uX'; - if ( ! $case_sensitive ) { - $modifiers .= 'i'; - } - if ( $multiline ) { - $modifiers .= 'm'; - } - if ( $dotall ) { - $modifiers .= 's'; - } - - /* - * In binary data, MySQL ends lines at CR, LF, VT and FF. No PCRE setting - * matches that. (*ANY) also ends lines at the byte 0x85, which is a part of - * characters like "ą" (0xC4 0x85). (*ANYCRLF) misses only the rare VT and FF. - */ - if ( $unix_lines ) { - $newline = '(*LF)'; - } elseif ( $binary_mode ) { - $newline = '(*ANYCRLF)'; - } else { - $newline = '(*ANY)'; - } - $compiled = '/' . $newline . $this->regexp_escape_pattern( $pattern, $without_g ) . '/' . $modifiers; + // The last "c" or "i" sets case sensitivity. MySQL's "n" and "u" mean ICU's dotall and Unix-lines modes. + $flags = 'c' === substr( rtrim( $match_type, 'mnu' ), -1 ) ? '' : 'i'; + $flags .= strtr( str_replace( array( 'c', 'i' ), '', $match_type ), 'nu', 'sd' ); + $compiled = WP_ICU_Regex_Translator::translate( $pattern, $flags, $without_g, $binary_mode ); - /* - * Compile the pattern by matching it against an empty string. Only a compile - * error emits a PHP warning, so silence it and report a MySQL error instead. - * A limit error concerns only the empty string, so the pattern is valid. - */ + // Probe the compiled pattern before caching it. A match limit on the empty subject + // can occur even when the pattern compiled successfully. set_error_handler( static function () {} ); try { $valid = false !== preg_match( $compiled, '' ) || PREG_INTERNAL_ERROR !== preg_last_error(); @@ -1352,71 +1292,6 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false, $w return $compiled; } - /** - * Escape pattern delimiters and NUL bytes that are not already escaped, read - * "\K" as "K", and, if asked, make "\G" never match. - * - * PHP before 8.2 rejects NUL bytes in patterns, so they become "\x00". - * - * @param string $pattern The regex pattern. - * @param bool $without_g Optional. Whether "\G" never matches. - * - * @return string Pattern safe to wrap in slash delimiters. - */ - private function regexp_escape_pattern( $pattern, $without_g = false ) { - $special = array( - '/' => '\\/', - "\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' ); - 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'; - } - - $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; - } - } - - // Close quoted text that runs to the end, so that a trailing backslash - // can't escape the delimiter. - if ( $quoted ) { - $escaped .= '\\E'; - } - return $escaped; - } - /** * Check whether a string is valid UTF-8. * @@ -1436,7 +1311,7 @@ private function regexp_is_utf8( $value ) { * @param bool $allow_past_end Whether the position may be one past the last character. * @param bool $byte_mode Whether every byte is a character. * - * @throws Exception If the position is out of range. + * @throws WP_ICU_Regex_Exception If the position is out of range. * @return int The byte offset. */ private function regexp_char_to_byte_offset( $subject, $position, $allow_past_end, $byte_mode ) { @@ -1453,7 +1328,7 @@ private function regexp_char_to_byte_offset( $subject, $position, $allow_past_en if ( $allow_past_end && $chars + 1 === $position ) { return $length; } - throw new Exception( 'Index out of bounds in regular expression search.' ); + throw new WP_ICU_Regex_Exception( 'Index out of bounds in regular expression search.', 3686 ); } /** @@ -1472,7 +1347,7 @@ private function regexp_char_to_byte_offset( $subject, $position, $allow_past_en * @param array $match_data The match, with offsets. * @param array $group_keys The pattern's group numbers and names, as array keys. * - * @throws Exception On an invalid group reference. + * @throws WP_ICU_Regex_Exception On an invalid group reference. * @return string The expanded replacement. */ private function regexp_expand_replacement( $replacement, $match_data, $group_keys ) { @@ -1492,7 +1367,7 @@ static function ( $parts ) use ( $match_data, $group_keys ) { return $match_data[ $name ][0] ?? ''; } if ( '' === $digits ) { - throw new Exception( 'A capture group has an invalid name.' ); + throw new WP_ICU_Regex_Exception( 'A capture group has an invalid name.', 3887 ); } for ( $length = strlen( $digits ); $length > 0; --$length ) { $group = (int) substr( $digits, 0, $length ); @@ -1500,7 +1375,7 @@ static function ( $parts ) use ( $match_data, $group_keys ) { return ( $match_data[ $group ][0] ?? '' ) . substr( $digits, $length ); } } - throw new Exception( 'Index out of bounds in regular expression search.' ); + throw new WP_ICU_Regex_Exception( 'Index out of bounds in regular expression search.', 3686 ); }, $replacement ); @@ -1555,15 +1430,6 @@ private function regexp_matches( $pattern, $match_type, $byte_mode, $subject, $o if ( ! $this->regexp_match( $search, $pattern, $subject, $match, PREG_OFFSET_CAPTURE, $offset ) ) { return; } - - /* - * 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. - */ - if ( $match[0][1] < $offset ) { - throw new Exception( 'Invalid regular expression: ' . $pattern . '.' ); - } yield $match; $offset = $match[0][1] + strlen( $match[0][0] ); @@ -1589,7 +1455,7 @@ private function regexp_matches( $pattern, $match_type, $byte_mode, $subject, $o * @param int $flags Optional. The preg_match() flags. * @param int $offset Optional. The byte offset to start at. * - * @throws Exception On a preg failure. + * @throws WP_ICU_Regex_Exception If PCRE cannot complete the match. * @return int 1 on match, 0 on no match. */ private function regexp_match( $compiled, $pattern, $subject, &$matches = null, $flags = 0, $offset = 0 ) { @@ -1610,14 +1476,11 @@ private function regexp_match( $compiled, $pattern, $subject, &$matches = null, } /** - * Translate a preg_* failure into a caller-friendly exception message. - * - * Uses preg_last_error() to distinguish invalid patterns from runtime - * limit failures. + * Map a PCRE failure to the corresponding driver error. * * @param string $pattern The original MySQL regex pattern. * - * @throws Exception Always. + * @throws WP_ICU_Regex_Exception Always. * @return void */ private function regexp_fail( $pattern ) { @@ -1627,8 +1490,10 @@ private function regexp_fail( $pattern ) { || PREG_RECURSION_LIMIT_ERROR === $err || PREG_JIT_STACKLIMIT_ERROR === $err ) { - throw new Exception( 'Regular expression evaluation exceeded internal limits.' ); + // Report backtracking as a MySQL timeout and recursion or JIT stack exhaustion as a stack overflow. + $code = PREG_BACKTRACK_LIMIT_ERROR === $err ? 3699 : 3698; + throw new WP_ICU_Regex_Exception( 'Regular expression evaluation exceeded internal limits.', $code ); } - throw new Exception( 'Invalid regular expression: ' . $pattern . '.' ); + throw new WP_ICU_Regex_Exception( 'Invalid regular expression: ' . $pattern . '.', 3688 ); } } 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 f57393ef7..4e785bed0 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 @@ -380,12 +380,11 @@ 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.' ), - 'ICU escape' => array( "REGEXP_LIKE('A', '\\\\u0041')", 'Invalid regular expression: \\u0041.' ), - '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.' ), + 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (abc.' ), + 'unknown escape' => array( "REGEXP_LIKE('N', '\\\\N')", 'SQLSTATE[HY000]: General error: 3690 Unsupported regular expression syntax: \\N' ), + 'bad property' => array( "REGEXP_LIKE('a', '\\\\p{Foo}')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: \\p{Foo}.' ), + 'operator escape' => array( "'N' REGEXP '\\\\N'", 'SQLSTATE[HY000]: General error: 3690 Unsupported regular expression syntax: \\N' ), + 'binary escape' => array( "X'FF' REGEXP '\\\\N'", 'SQLSTATE[HY000]: General error: 3690 Unsupported regular expression syntax: \\N' ), 'extra argument' => array( "REGEXP_LIKE('abc', 'abc', 'c', 'extra')", 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_LIKE()', @@ -468,7 +467,7 @@ public function testRegexpBacktrackLimit() { $subject = str_repeat( 'a', 30 ); $this->assertQueryError( "SELECT REGEXP_LIKE('$subject', '^(a?){30}a{30}\$')", - 'Regular expression evaluation exceeded internal limits.' + 'SQLSTATE[HY000]: General error: 3699 Regular expression evaluation exceeded internal limits.' ); } @@ -489,7 +488,7 @@ public function testRegexpLimitOnlyOnEmptySubject() { ); $this->assertQueryError( "SELECT REGEXP_LIKE('', '$pattern')", - 'Regular expression evaluation exceeded internal limits.' + 'SQLSTATE[HY000]: General error: 3699 Regular expression evaluation exceeded internal limits.' ); } @@ -502,7 +501,7 @@ public function testRegexpJitStackLimit() { $this->iniSet( 'pcre.recursion_limit', '1000' ); $this->assertQueryError( "SELECT REGEXP_LIKE('$subject', '^(a|b)*\$')", - 'Regular expression evaluation exceeded internal limits.' + 'SQLSTATE[HY000]: General error: 3698 Regular expression evaluation exceeded internal limits.' ); return; } @@ -536,7 +535,7 @@ public function testRegexpLimitWithoutJit() { $subject = str_repeat( 'a', 200000 ); $this->assertQueryError( "SELECT REGEXP_LIKE('$subject', '^(a|b)*\$')", - 'Regular expression evaluation exceeded internal limits.' + 'SQLSTATE[HY000]: General error: 3698 Regular expression evaluation exceeded internal limits.' ); } @@ -558,11 +557,11 @@ public function testRegexpLegacyOperatorNullPropagation() { public function testRegexpLegacyOperatorInvalidPattern() { $this->assertQueryError( "SELECT 'abc' REGEXP '(abc'", - 'Invalid regular expression: (abc.' + 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (abc.' ); $this->assertQueryError( "SELECT 'abc' RLIKE ''", - 'Illegal argument to a regular expression.' + 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ); } @@ -782,27 +781,103 @@ public function testRegexpLikeEscapedDelimiter() { $this->assertSame( '1', $this->last_result[0]->r ); } - public function testRegexpEscapedKIsLiteral() { - // Like ICU, read "\K" as "K", also in a set. In quoted text, it stays "\K". - $this->assertQuery( - "SELECT - REGEXP_LIKE('K', '\\\\K') AS letter, - REGEXP_LIKE('ab', 'a\\\\Kb') AS no_reset, - 'aKb' REGEXP 'a\\\\Kb' AS operator_result, - REGEXP_LIKE('K', '[\\\\K]') AS in_set, - REGEXP_LIKE('\\\\K', '^\\\\Q\\\\K\\\\E\$') AS quoted" + /** + * @dataProvider regexpIcuSyntaxCases + */ + public function testRegexpIcuSyntax( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpIcuSyntaxCases() { + return array( + 'code point escape' => array( "REGEXP_LIKE('A', '\\\\u0041')", '1' ), + 'word character with an accent' => array( "REGEXP_SUBSTR('-éa-', '\\\\w+')", 'éa' ), + 'POSIX class' => array( "REGEXP_SUBSTR('1aé2', '[[:alpha:]]+')", 'aé' ), + 'set before a CRLF' => array( "REGEXP_LIKE('dog\\r\\ncat', '[^a-z]cat')", '1' ), + 'no line end inside a CRLF' => array( "HEX(REGEXP_REPLACE('a\\r\\n', '\$', '!'))", '61210D0A21' ), + 'negated set of one character' => array( "REGEXP_REPLACE('日本s', '[^s]', '-')", '--s' ), + 'quoted text' => array( "REGEXP_LIKE('\\\\K', '^\\\\Q\\\\K\\\\E\$')", '1' ), + + // ICU treats "\K" as a literal K. PCRE uses it to reset the match start. + 'escaped letter' => array( "REGEXP_LIKE('y', '^\\\\y\$')", '1' ), + 'escaped K' => array( "REGEXP_SUBSTR('aKb', 'a\\\\K')", 'aK' ), + 'escaped K, no reset' => array( "REGEXP_REPLACE('ab', 'a\\\\Kb', '!')", 'ab' ), + 'escaped K, operator' => array( "'aKb' REGEXP 'a\\\\Kb'", '1' ), + 'escaped K, in a set' => array( "REGEXP_LIKE('K', '[\\\\K]')", '1' ), + 'escaped K, binary' => array( "REGEXP_LIKE(X'4BFF', '\\\\K')", '1' ), + + 'look-behind' => array( "REGEXP_SUBSTR('price: 42', '(?<=: )\\\\d+')", '42' ), + 'look-behind with alternatives' => array( "REGEXP_REPLACE('my acct', '(? array( "HEX(REGEXP_REPLACE('abc\\nabc', '.*b', '!'))", '21630A2163' ), + 'leading dot-star, from pos' => array( "REGEXP_SUBSTR('abc\\nabc', '.*c', 2)", 'bc' ), + 'leading dot-star, occurrence' => array( "REGEXP_INSTR('abc\\nabc', '.*c', 2, 2)", '5' ), + 'leading dot-plus, from pos' => array( "REGEXP_SUBSTR('abc\\nabc', '.+c', 3)", 'abc' ), + 'leading dot-star, in a group' => array( "REGEXP_REPLACE('abc\\nabc', '(.*)c', '[$1]', 2)", "a[b]\n[ab]" ), + 'dot with a count' => array( "REGEXP_SUBSTR('-cba', 'c?-.{2}')", '-cb' ), + + // MySQL 8 rejects these, but MySQL 5.7 and MariaDB accept them. + 'legacy word boundaries' => array( "REGEXP_LIKE('a cat', '[[:<:]]cat[[:>:]]')", '1' ), + 'legacy word boundaries, binary' => array( "REGEXP_LIKE(X'6120636174FF', '[[:<:]]cat[[:>:]]')", '1' ), + 'literal braces' => array( "REGEXP_LIKE('a{b}', 'a{b}')", '1' ), ); - $this->assertEquals( - array( - (object) array( - 'letter' => '1', - 'no_reset' => '0', - 'operator_result' => '1', - 'in_set' => '1', - 'quoted' => '1', - ), - ), - $this->last_result + } + + /** + * @dataProvider regexpUnsupportedSyntaxCases + */ + public function testRegexpUnsupportedSyntax( $sql, $syntax ) { + $this->assertQueryError( "SELECT $sql", "SQLSTATE[HY000]: General error: 3690 Unsupported regular expression syntax: $syntax" ); + } + + public static function regexpUnsupportedSyntaxCases() { + return array( + 'named character' => array( "REGEXP_LIKE('N', '\\\\N')", '\\N' ), + 'named character, in a set' => array( "REGEXP_LIKE('N', '[\\\\N]')", '\\N' ), + 'named character, operator' => array( "'aNb' REGEXP 'a\\\\Nb'", '\\N' ), + 'named character, binary' => array( "REGEXP_LIKE(X'FF', '\\\\N')", '\\N' ), + 'REGEXP_REPLACE' => array( "REGEXP_REPLACE('ab', 'a\\\\N', 'X')", '\\N' ), + 'REGEXP_SUBSTR' => array( "REGEXP_SUBSTR('ab', 'a\\\\N', 1, 2)", '\\N' ), + 'REGEXP_INSTR' => array( "REGEXP_INSTR('ab', 'a\\\\N')", '\\N' ), + 'extended flag' => array( "REGEXP_LIKE('ab', '(?x) a b')", '(?x' ), + 'PCRE named group' => array( "REGEXP_LIKE('a', '(?Pa)')", '(?P' ), + 'PCRE verb' => array( "REGEXP_LIKE('ab', 'a(*ACCEPT)b')", '*' ), + 'nested set' => array( "REGEXP_LIKE('b', '[a[bc]]')", '[' ), + 'set operator' => array( "REGEXP_LIKE('b', '[a-z&&[^aeiou]]')", '[' ), + 'look-behind of any length' => array( "REGEXP_LIKE('aab', '(?<=a+)b')", '(?<=' ), + 'empty quoted text' => array( "REGEXP_LIKE('', '\\\\Q')", '\\Q' ), + 'comment with a backslash' => array( "REGEXP_SUBSTR('aa', '(?#\\\\G)a', 2)", '(?#' ), + ); + } + + /** + * @dataProvider regexpErrorNumbers + */ + public function testRegexpErrorsHaveMysqlErrorNumbers( $sql, $code, $message ) { + $exception = null; + try { + $this->query( "SELECT $sql" ); + } catch ( WP_MySQL_On_SQLite_Exception $e ) { + $exception = $e; + } + $this->assertNotNull( $exception, 'An exception was expected, but none was thrown.' ); + $this->assertSame( "SQLSTATE[HY000]: General error: $code $message", $exception->getMessage() ); + $this->assertSame( 'HY000', $exception->getCode() ); + $this->assertSame( array( 'HY000', $code, $message ), $exception->errorInfo ); + $this->assertSame( array( 'HY000', $code, $message ), $this->engine->errorInfo() ); + } + + public static function regexpErrorNumbers() { + $limit = 'Regular expression evaluation exceeded internal limits.'; + return array( + 'empty pattern' => array( "REGEXP_LIKE('abc', '')", 3685, 'Illegal argument to a regular expression.' ), + 'empty pattern, operator' => array( "'abc' REGEXP ''", 3685, 'Illegal argument to a regular expression.' ), + 'pos past the end' => array( "REGEXP_INSTR('abc', 'a', 5)", 3686, 'Index out of bounds in regular expression search.' ), + 'group past the last one' => array( "REGEXP_REPLACE('abc', 'a', '\$1')", 3686, 'Index out of bounds in regular expression search.' ), + 'invalid pattern' => array( "REGEXP_LIKE('abc', '(abc')", 3688, 'Invalid regular expression: (abc.' ), + 'unsupported syntax' => array( "REGEXP_LIKE('abc', '(?x)abc')", 3690, 'Unsupported regular expression syntax: (?x' ), + 'time limit' => array( "REGEXP_LIKE('" . str_repeat( 'a', 30 ) . "', '^(a?){30}a{30}\$')", 3699, $limit ), + 'unknown group name' => array( "REGEXP_REPLACE('abc', 'a', '\${x}')", 3887, 'A capture group has an invalid name.' ), ); } @@ -823,7 +898,6 @@ public static function regexpUnterminatedQuoteCases() { 'two trailing backslashes' => array( "REGEXP_LIKE('a\\\\\\\\', '^\\\\Qa\\\\\\\\')", '1' ), 'literal dot' => array( "REGEXP_LIKE('a.b', '^\\\\Qa.b')", '1' ), 'literal dot, no match' => array( "REGEXP_LIKE('axb', '^\\\\Qa.b')", '0' ), - 'empty' => array( "REGEXP_LIKE('', '\\\\Q')", '1' ), ); } @@ -885,12 +959,12 @@ public static function regexpReplaceErrors() { 'pos zero, NULL subject' => array( "REGEXP_REPLACE(NULL, 'a', 'X', 0)", $pos_error ), 'pos zero, NULL pattern' => array( "REGEXP_REPLACE('abc', NULL, 'X', 0)", $pos_error ), 'pos zero, NULL replacement' => array( "REGEXP_REPLACE('abc', 'a', NULL, 0)", $pos_error ), - 'invalid pattern, pos zero' => array( "REGEXP_REPLACE('abc', '(', 'X', 0)", 'Invalid regular expression: (.' ), - 'invalid pattern, NULL subject' => array( "REGEXP_REPLACE(NULL, '(', 'X')", 'Invalid regular expression: (.' ), - 'invalid pattern, NULL pos' => array( "REGEXP_REPLACE('abc', '(', 'X', NULL)", 'Invalid regular expression: (.' ), - 'empty pattern, NULL subject' => array( "REGEXP_REPLACE(NULL, '', 'X')", 'Illegal argument to a regular expression.' ), - 'pos two past end' => array( "REGEXP_REPLACE('abc', 'a', 'X', 5)", 'Index out of bounds in regular expression search.' ), - 'pos far past end' => array( "REGEXP_REPLACE('abc', 'a', 'X', 10)", 'Index out of bounds in regular expression search.' ), + 'invalid pattern, pos zero' => array( "REGEXP_REPLACE('abc', '(', 'X', 0)", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'invalid pattern, NULL subject' => array( "REGEXP_REPLACE(NULL, '(', 'X')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'invalid pattern, NULL pos' => array( "REGEXP_REPLACE('abc', '(', 'X', NULL)", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'empty pattern, NULL subject' => array( "REGEXP_REPLACE(NULL, '', 'X')", 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ), + 'pos two past end' => array( "REGEXP_REPLACE('abc', 'a', 'X', 5)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), + 'pos far past end' => array( "REGEXP_REPLACE('abc', 'a', 'X', 10)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), 'invalid match type' => array( "REGEXP_REPLACE('abc', 'a', 'X', 1, 0, 'x')", 'Incorrect arguments to regexp_replace' ), 'invalid match type, NULL subject' => array( "REGEXP_REPLACE(NULL, 'a', 'X', 1, 0, 'x')", 'Incorrect arguments to regexp_replace' ), 'invalid match type, NULL replacement' => array( "REGEXP_REPLACE('abc', 'a', NULL, 1, 0, 'x')", 'Incorrect arguments to regexp_replace' ), @@ -964,7 +1038,7 @@ public function testRegexpReplaceBraceBackrefIsInvalid() { // MySQL/ICU rejects "${N}"; only named groups are referenced with braces. $this->assertQueryError( "SELECT REGEXP_REPLACE('abc', '(a)(b)(c)', '\${2}\${1}', 1, 1)", - 'A capture group has an invalid name.' + 'SQLSTATE[HY000]: General error: 3887 A capture group has an invalid name.' ); } @@ -1005,7 +1079,7 @@ public function testRegexpReplaceInvalidNamedGroupReference() { list( $pattern, $replacement ) = $case; $this->assertQueryError( "SELECT REGEXP_REPLACE('abc', '$pattern', '$replacement')", - 'A capture group has an invalid name.' + 'SQLSTATE[HY000]: General error: 3887 A capture group has an invalid name.' ); } } @@ -1037,14 +1111,14 @@ public function testRegexpReplaceDollarDigitGreedyFallback() { public function testRegexpReplaceDollarWithoutDigitErrors() { $this->assertQueryError( "SELECT REGEXP_REPLACE('abc', 'b', 'x\$y')", - 'A capture group has an invalid name.' + 'SQLSTATE[HY000]: General error: 3887 A capture group has an invalid name.' ); } public function testRegexpReplaceDollarOutOfBoundsErrors() { $this->assertQueryError( "SELECT REGEXP_REPLACE('abc', '(b)', '[\$9]')", - 'Index out of bounds in regular expression search.' + 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ); } @@ -1142,19 +1216,16 @@ public static function regexpMatchEndAnchorCases() { 'REGEXP_REPLACE, after empty match' => array( "REGEXP_REPLACE('000123', '\\\\G0*', 'x')", 'xx123' ), 'REGEXP_REPLACE, pos' => array( "REGEXP_REPLACE('aab', '\\\\Ga', '-', 2)", 'aab' ), '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_SUBSTR, after empty match' => array( "REGEXP_SUBSTR('abc', '\\\\G', 1, 2)", null ), 'REGEXP_SUBSTR, pos' => array( "REGEXP_SUBSTR('abc', '\\\\G.', 2)", null ), - 'REGEXP_SUBSTR, in a comment' => array( "REGEXP_SUBSTR('aa', '(?#\\\\G)a', 2)", 'a' ), 'REGEXP_SUBSTR, second occurrence' => array( "REGEXP_SUBSTR('abc', '\\\\G.', 1, 2)", 'b' ), // REGEXP_INSTR() searches the subject from pos on, as if it started there. 'REGEXP_INSTR, after empty match' => array( "REGEXP_INSTR('abc', '\\\\G', 1, 2)", '0' ), 'REGEXP_INSTR, pos' => array( "REGEXP_INSTR('abc', '\\\\G.', 2)", '2' ), 'REGEXP_INSTR, second occurrence' => array( "REGEXP_INSTR('abc', '\\\\G.', 2, 2)", '3' ), - 'REGEXP_INSTR, in a comment' => array( "REGEXP_INSTR('aa', '(?#\\\\G)a', 1, 2)", '2' ), ); } @@ -1202,11 +1273,11 @@ public static function regexpSubstrErrors() { // Like MySQL, check the pattern and pos before NULL arguments make the result NULL. $pos_error = "Incorrect parameters in the call to native function 'regexp_substr'"; return array( - 'invalid pattern' => array( "REGEXP_SUBSTR('abc', '(abc')", 'Invalid regular expression: (abc.' ), - 'invalid pattern, pos zero' => array( "REGEXP_SUBSTR('abc', '(', 0)", 'Invalid regular expression: (.' ), - 'invalid pattern, NULL subject' => array( "REGEXP_SUBSTR(NULL, '(')", 'Invalid regular expression: (.' ), - 'invalid pattern, NULL occurrence' => array( "REGEXP_SUBSTR('abc', '(', 1, NULL)", 'Invalid regular expression: (.' ), - 'empty pattern, NULL subject' => array( "REGEXP_SUBSTR(NULL, '')", 'Illegal argument to a regular expression.' ), + 'invalid pattern' => array( "REGEXP_SUBSTR('abc', '(abc')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (abc.' ), + 'invalid pattern, pos zero' => array( "REGEXP_SUBSTR('abc', '(', 0)", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'invalid pattern, NULL subject' => array( "REGEXP_SUBSTR(NULL, '(')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'invalid pattern, NULL occurrence' => array( "REGEXP_SUBSTR('abc', '(', 1, NULL)", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'empty pattern, NULL subject' => array( "REGEXP_SUBSTR(NULL, '')", 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ), 'invalid match type' => array( "REGEXP_SUBSTR('abc', 'a', 1, 1, 'x')", 'Incorrect arguments to regexp_substr' ), 'invalid match type, NULL subject' => array( "REGEXP_SUBSTR(NULL, 'a', 1, 1, 'x')", 'Incorrect arguments to regexp_substr' ), 'invalid match type, NULL pos' => array( "REGEXP_SUBSTR('abc', 'a', NULL, 1, 'x')", 'Incorrect arguments to regexp_substr' ), @@ -1215,8 +1286,8 @@ public static function regexpSubstrErrors() { 'pos zero, empty subject' => array( "REGEXP_SUBSTR('', 'a', 0)", $pos_error ), 'pos zero, NULL subject' => array( "REGEXP_SUBSTR(NULL, 'a', 0)", $pos_error ), 'pos zero, NULL pattern' => array( "REGEXP_SUBSTR('abc', NULL, 0)", $pos_error ), - 'pos two past end' => array( "REGEXP_SUBSTR('abc', 'a', 5)", 'Index out of bounds in regular expression search.' ), - 'pos far past end' => array( "REGEXP_SUBSTR('abc', 'a', 10)", 'Index out of bounds in regular expression search.' ), + 'pos two past end' => array( "REGEXP_SUBSTR('abc', 'a', 5)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), + 'pos far past end' => array( "REGEXP_SUBSTR('abc', 'a', 10)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), 'extra argument' => array( "REGEXP_SUBSTR('abc', 'a', 1, 1, 'c', 'extra')", 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_SUBSTR()', @@ -1283,18 +1354,18 @@ public function testRegexpInstrErrors( $sql, $message ) { public static function regexpInstrErrors() { $return_option = 'Incorrect arguments to regexp_instr: return_option must be 1 or 0.'; return array( - 'invalid pattern' => array( "REGEXP_INSTR('abc', '(abc')", 'Invalid regular expression: (abc.' ), + 'invalid pattern' => array( "REGEXP_INSTR('abc', '(abc')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (abc.' ), // Like MySQL, check the pattern before NULL arguments make the result NULL. - 'invalid pattern, NULL subject' => array( "REGEXP_INSTR(NULL, '(')", 'Invalid regular expression: (.' ), - 'invalid pattern, NULL return_option' => array( "REGEXP_INSTR('abc', '(', 1, 1, NULL)", 'Invalid regular expression: (.' ), - 'empty pattern, NULL subject' => array( "REGEXP_INSTR(NULL, '')", 'Illegal argument to a regular expression.' ), + 'invalid pattern, NULL subject' => array( "REGEXP_INSTR(NULL, '(')", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'invalid pattern, NULL return_option' => array( "REGEXP_INSTR('abc', '(', 1, 1, NULL)", 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ), + 'empty pattern, NULL subject' => array( "REGEXP_INSTR(NULL, '')", 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ), 'invalid match type' => array( "REGEXP_INSTR('abc', 'a', 1, 1, 0, 'x')", 'Incorrect arguments to regexp_instr' ), 'invalid match type, NULL subject' => array( "REGEXP_INSTR(NULL, 'a', 1, 1, 0, 'x')", 'Incorrect arguments to regexp_instr' ), 'invalid match type, NULL return_option' => array( "REGEXP_INSTR('abc', 'a', 1, 1, NULL, 'x')", 'Incorrect arguments to regexp_instr' ), - 'pos zero' => array( "REGEXP_INSTR('abc', 'a', 0)", 'Index out of bounds in regular expression search.' ), + 'pos zero' => array( "REGEXP_INSTR('abc', 'a', 0)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), // Unlike REGEXP_SUBSTR() and REGEXP_REPLACE(), pos can't be one past the end. - 'pos one past end' => array( "REGEXP_INSTR('abc', 'a', 4)", 'Index out of bounds in regular expression search.' ), - 'pos far past end' => array( "REGEXP_INSTR('abc', 'a', 10)", 'Index out of bounds in regular expression search.' ), + 'pos one past end' => array( "REGEXP_INSTR('abc', 'a', 4)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), + 'pos far past end' => array( "REGEXP_INSTR('abc', 'a', 10)", 'SQLSTATE[HY000]: General error: 3686 Index out of bounds in regular expression search.' ), 'invalid return_option' => array( "REGEXP_INSTR('abc', 'a', 1, 1, 2)", $return_option ), 'invalid return_option, NULL subject' => array( "REGEXP_INSTR(NULL, 'a', 1, 1, 2)", $return_option ), 'invalid return_option, NULL match type' => array( "REGEXP_INSTR('abc', 'a', 1, 1, 2, NULL)", $return_option ), @@ -1320,7 +1391,7 @@ public function testRegexpInstrEmptySubjectSkipsPosCheck() { $this->assertQueryError( "SELECT REGEXP_INSTR('', '(', 2)", - 'Invalid regular expression: (.' + 'SQLSTATE[HY000]: General error: 3688 Invalid regular expression: (.' ); } @@ -1362,19 +1433,19 @@ public function testRegexpEmptyPatternRejected() { // MySQL rejects the empty pattern with ERROR 3685. $this->assertQueryError( "SELECT REGEXP_LIKE('abc', '')", - 'Illegal argument to a regular expression.' + 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ); $this->assertQueryError( "SELECT REGEXP_REPLACE('abc', '', 'x')", - 'Illegal argument to a regular expression.' + 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ); $this->assertQueryError( "SELECT REGEXP_SUBSTR('abc', '')", - 'Illegal argument to a regular expression.' + 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ); $this->assertQueryError( "SELECT REGEXP_INSTR('abc', '')", - 'Illegal argument to a regular expression.' + 'SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression.' ); } @@ -1422,54 +1493,6 @@ public function testRegexpAstralPlaneCharacter() { $this->assertSame( '3', $this->last_result[0]->r ); } - public function testRegexpEscapedKInLookbehind() { - // "\K" is a literal "K". In PCRE, it could move the start of a match in a lookbehind - // to before the search, so that the next search found the same match forever. - $this->assertQuery( - "SELECT - REGEXP_REPLACE('ab', '(?<=\\\\Ka)', 'X') AS replace_result, - REGEXP_REPLACE('Kab', '(?<=\\\\Ka)', 'X') AS replace_after_k, - REGEXP_SUBSTR('ab', '(?<=\\\\Ka)', 1, 2) AS substr_result, - REGEXP_INSTR('Kab', '(?<=\\\\Ka)') AS instr_result" - ); - $this->assertEquals( - array( - (object) array( - 'replace_result' => 'ab', - 'replace_after_k' => 'KaXb', - 'substr_result' => null, - 'instr_result' => '3', - ), - ), - $this->last_result - ); - } - - /** - * @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. - $this->assertQueryError( - 'SELECT ' . sprintf( $sql, $this->engine->quote( $pattern ) ), - "Invalid regular expression: $pattern." - ); - } - - public static function regexpQuoteInCommentCases() { - $comment = '(?#\Q)(?<=\Ka)'; - $extended = "(?x)#\\Q\n(?<=\\Ka)"; - return array( - 'REGEXP_REPLACE, comment' => array( "REGEXP_REPLACE('ab', %s, 'X')", $comment ), - 'REGEXP_REPLACE, extended comment' => array( "REGEXP_REPLACE('ab', %s, 'X')", $extended ), - 'REGEXP_SUBSTR, comment' => array( "REGEXP_SUBSTR('ab', %s, 1, 2)", $comment ), - 'REGEXP_SUBSTR, extended comment' => array( "REGEXP_SUBSTR('ab', %s, 1, 2)", $extended ), - 'REGEXP_INSTR, comment' => array( "REGEXP_INSTR('ab', %s, 1, 2)", $comment ), - 'REGEXP_INSTR, extended comment' => array( "REGEXP_INSTR('ab', %s, 1, 2)", $extended ), - ); - } - /** * @dataProvider regexpBigIntegerCases */ 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..0549a998a 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,250 +14,11 @@ 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: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', - 'mysql-server-suite:12328', - 'mysql-server-suite:12329', - 'mysql-server-suite:12330', - 'mysql-server-suite:12331', - 'mysql-server-suite:12332', - 'mysql-server-suite:12333', - 'mysql-server-suite:12334', - 'mysql-server-suite:12335', - 'mysql-server-suite:12336', - 'mysql-server-suite:12337', - 'mysql-server-suite:12338', - 'mysql-server-suite:12339', - 'mysql-server-suite:12340', - 'mysql-server-suite:12341', - 'mysql-server-suite:12342', - 'mysql-server-suite:12343', - 'mysql-server-suite:12344', - 'mysql-server-suite:12345', - 'mysql-server-suite:12346', - 'mysql-server-suite:12347', - 'mysql-server-suite:12348', - 'mysql-server-suite:12349', - 'mysql-server-suite:12350', - 'mysql-server-suite:12351', - 'mysql-server-suite:12352', - 'mysql-server-suite:12353', - 'mysql-server-suite:12354', - 'mysql-server-suite:12355', - 'mysql-server-suite:12356', - 'mysql-server-suite:12357', - 'mysql-server-suite:12358', - 'mysql-server-suite:12359', - 'mysql-server-suite:12360', - 'mysql-server-suite:12361', - 'mysql-server-suite:12362', - 'mysql-server-suite:12363', - 'mysql-server-suite:12364', - 'mysql-server-suite:12365', - 'mysql-server-suite:12366', - 'mysql-server-suite:12367', - 'mysql-server-suite:12368', - 'mysql-server-suite:12369', - 'mysql-server-suite:12370', - 'mysql-server-suite:12371', - 'mysql-server-suite:12372', - 'mysql-server-suite:12373', - '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', - 'mysql-server-suite:12592', - 'mysql-server-suite:12593', - 'mysql-server-suite:12594', - 'mysql-server-suite:12595', - 'mysql-server-suite:12596', - 'mysql-server-suite:12597', - 'mysql-server-suite:12598', - 'mysql-server-suite:12599', - 'mysql-server-suite:12600', - 'mysql-server-suite:12601', - 'mysql-server-suite:12602', - 'mysql-server-suite:12603', - 'mysql-server-suite:12604', - 'mysql-server-suite:12605', - 'mysql-server-suite:12606', - 'mysql-server-suite:12607', - 'mysql-server-suite:12608', - 'mysql-server-suite:12609', - 'mysql-server-suite:12610', - 'mysql-server-suite:12611', - 'mysql-server-suite:12612', - 'icu-regextst:133', - 'icu-regextst:134', - 'icu-regextst:135', - 'icu-regextst:136', - 'icu-regextst:146', - 'icu-regextst:147', - 'icu-regextst:148', - 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', - 'icu-regextst:219', - 'icu-regextst:220', - 'icu-regextst:221', - 'icu-regextst:222', - 'icu-regextst:223', - 'icu-regextst:224', - 'icu-regextst:227', - 'icu-regextst:228', - 'icu-regextst:229', - 'icu-regextst:230', - 'icu-regextst:231', - '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', - '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', - 'icu-regextst:523', + // MySQL reports a duplicate capture name as 3887. The driver reports a syntax error (3688). 'icu-regextst:524', 'icu-regextst:525', + + // PCRE case folding cannot match one character against several, such as "ß" against "ss". 'icu-regextst:538', 'icu-regextst:539', 'icu-regextst:540', @@ -268,207 +29,6 @@ protected function get_known_failures(): array { 'icu-regextst:545', 'icu-regextst:546', 'icu-regextst:547', - 'icu-regextst:564', - 'icu-regextst:565', - 'icu-regextst:566', - 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', - 'icu-regextst:590', - 'icu-regextst:591', - 'icu-regextst:626', - 'icu-regextst:627', - 'icu-regextst:628', - 'icu-regextst:629', - 'icu-regextst:630', - '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', - 'icu-regextst:726', - 'icu-regextst:727', - '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', - 'icu-regextst:942', - 'icu-regextst:949', - '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:1055', - 'icu-regextst:1056', - 'icu-regextst:1057', - 'icu-regextst:1058', - 'icu-regextst:1065', - 'icu-regextst:1066', - 'icu-regextst:1081', - 'icu-regextst:1082', - 'icu-regextst:1083', - 'icu-regextst:1084', - 'icu-regextst:1085', - 'icu-regextst:1086', - 'icu-regextst:1087', - 'icu-regextst:1088', - 'icu-regextst:1089', - 'icu-regextst:1090', - 'icu-regextst:1091', - 'icu-regextst:1092', - 'icu-regextst:1093', - 'icu-regextst:1094', - 'icu-regextst:1095', - 'icu-regextst:1096', - 'icu-regextst:1097', - 'icu-regextst:1098', - 'icu-regextst:1099', - 'icu-regextst:1100', - 'icu-regextst:1101', - 'icu-regextst:1102', - 'icu-regextst:1103', - 'icu-regextst:1104', - 'icu-regextst:1105', - 'icu-regextst:1106', - 'icu-regextst:1107', - 'icu-regextst:1108', - 'icu-regextst:1109', - 'icu-regextst:1110', - 'icu-regextst:1111', - 'icu-regextst:1112', - 'icu-regextst:1113', - 'icu-regextst:1114', - 'icu-regextst:1115', - 'icu-regextst:1116', - 'icu-regextst:1117', - 'icu-regextst:1118', - 'icu-regextst:1119', - 'icu-regextst:1120', - 'icu-regextst:1121', - 'icu-regextst:1122', - 'icu-regextst:1123', - 'icu-regextst:1124', - 'icu-regextst:1125', - 'icu-regextst:1126', - 'icu-regextst:1127', - 'icu-regextst:1128', - 'icu-regextst:1129', - 'icu-regextst:1130', - 'icu-regextst:1131', - 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', - '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', - 'icu-regextst:1180', - 'icu-regextst:1181', - 'icu-regextst:1182', - 'icu-regextst:1185', - 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -481,10 +41,6 @@ protected function get_known_failures(): array { 'icu-regextst:1240', 'icu-regextst:1241', 'icu-regextst:1242', - 'icu-regextst:1243', - 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -495,342 +51,46 @@ protected function get_known_failures(): array { 'icu-regextst:1256', 'icu-regextst:1259', 'icu-regextst:1260', - 'icu-regextst:1261', - '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:1318', - 'icu-regextst:1319', - 'icu-regextst:1330', - 'icu-regextst:1331', - 'icu-regextst:1332', - 'icu-regextst:1333', - 'icu-regextst:1334', - 'icu-regextst:1335', - 'icu-regextst:1336', - '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', - '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', + + // Case folding changes the matched text even though both engines find a match. + 'icu-regextst:1243', + 'icu-regextst:1244', + 'icu-regextst:1261', + 'icu-regextst:1262', + + // ICU accepts UTF-16 surrogate escapes. The translation emits each surrogate separately, which PCRE rejects. + 'icu-regextst:715', + 'icu-regextst:716', + 'icu-regextst:717', + 'icu-regextst:718', + 'icu-regextst:719', + 'icu-regextst:720', + + // The translator reads names such as Inbasiclatin and Letter as scripts, which PCRE rejects (3688). + 'icu-regextst:1093', + 'icu-regextst:1094', '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', - 'icu-regextst:1425', - 'icu-regextst:1426', - 'icu-regextst:1427', - 'icu-regextst:1428', - 'icu-regextst:1429', - 'icu-regextst:1430', - 'icu-regextst:1431', - 'icu-regextst:1432', - 'icu-regextst:1433', 'icu-regextst:1434', 'icu-regextst:1435', - 'icu-regextst:1436', - 'icu-regextst:1437', - 'icu-regextst:1438', - 'icu-regextst:1439', - 'icu-regextst:1440', - 'icu-regextst:1441', - 'icu-regextst:1442', - 'icu-regextst:1443', - 'icu-regextst:1444', - 'icu-regextst:1445', - 'icu-regextst:1446', - 'icu-regextst:1447', + + // MySQL reports error 4007 for oversized repetition counts and 3685 for the property names In and Is. + 'icu-regextst:1334', + 'icu-regextst:1335', + 'icu-regextst:1336', + 'icu-regextst:1337', 'icu-regextst:1448', 'icu-regextst:1449', 'icu-regextst:1450', 'icu-regextst:1451', - 'icu-regextst:1454', - 'icu-regextst:1455', - 'icu-regextst:1456', - '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', + + // The driver normalizes the subject '2002-4-30' to '2002-04-30' before matching. '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', ); - // 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( - $failures, - 'icu-regextst:45', - 'icu-regextst:46', - 'icu-regextst:1496', - 'icu-regextst:1497' - ); - } - // PCRE 8 splits some grapheme clusters for \X, like an emoji with a skin tone, which ICU and PCRE2 keep whole. if ( ! $is_pcre2 ) { array_push( @@ -849,157 +109,6 @@ protected function get_known_failures(): array { ); } - // Binary Unicode properties, like \p{Alphabetic}, arrived in PCRE2 10.40. - if ( version_compare( $pcre_version, '10.40', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:12377', - 'mysql-server-suite:12378', - 'mysql-server-suite:12379', - 'mysql-server-suite:12380', - 'mysql-server-suite:12381', - 'mysql-server-suite:12382', - 'mysql-server-suite:12383', - 'mysql-server-suite:12384', - 'mysql-server-suite:12385', - 'mysql-server-suite:12386', - 'mysql-server-suite:12387', - 'mysql-server-suite:12388', - 'mysql-server-suite:12389', - 'mysql-server-suite:12390', - 'mysql-server-suite:12391', - 'mysql-server-suite:12392', - 'mysql-server-suite:12393', - 'mysql-server-suite:12394', - 'mysql-server-suite:12395', - 'mysql-server-suite:12396', - 'mysql-server-suite:12397', - 'mysql-server-suite:12398', - 'mysql-server-suite:12399', - 'mysql-server-suite:12400', - 'mysql-server-suite:12401', - 'mysql-server-suite:12402', - 'mysql-server-suite:12403', - 'mysql-server-suite:12404', - 'mysql-server-suite:12405', - 'mysql-server-suite:12406', - 'mysql-server-suite:12407', - 'mysql-server-suite:12408', - 'mysql-server-suite:12409', - 'mysql-server-suite:12410', - 'mysql-server-suite:12411', - 'mysql-server-suite:12412', - 'mysql-server-suite:12413', - 'mysql-server-suite:12414', - 'mysql-server-suite:12415', - 'mysql-server-suite:12416', - 'mysql-server-suite:12417', - 'mysql-server-suite:12418', - 'mysql-server-suite:12419', - 'mysql-server-suite:12420', - 'mysql-server-suite:12421', - 'mysql-server-suite:12422', - 'mysql-server-suite:12423', - 'mysql-server-suite:12424', - 'mysql-server-suite:12425', - 'mysql-server-suite:12426', - 'mysql-server-suite:12427', - 'mysql-server-suite:12428', - 'mysql-server-suite:12429', - 'mysql-server-suite:12430', - 'mysql-server-suite:12431', - 'mysql-server-suite:12432', - 'mysql-server-suite:12433', - 'mysql-server-suite:12434', - 'mysql-server-suite:12435', - 'mysql-server-suite:12436', - 'mysql-server-suite:12437', - 'mysql-server-suite:12438', - 'mysql-server-suite:12439', - 'mysql-server-suite:12440', - 'mysql-server-suite:12441', - 'mysql-server-suite:12442', - 'mysql-server-suite:12443', - 'mysql-server-suite:12444', - 'mysql-server-suite:12445', - 'mysql-server-suite:12446', - 'mysql-server-suite:12447', - 'mysql-server-suite:12448', - 'mysql-server-suite:12449', - 'mysql-server-suite:12450', - 'mysql-server-suite:12451', - 'mysql-server-suite:12452', - 'mysql-server-suite:12453', - 'mysql-server-suite:12454', - 'icu-regextst:1452', - 'icu-regextst:1453' - ); - } - - // Lookbehinds of variable length, like "(?<=bc?c?c?)", arrived in PCRE2 10.43. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'icu-regextst:612', - 'icu-regextst:613', - 'icu-regextst:614', - 'icu-regextst:615', - 'icu-regextst:616', - 'icu-regextst:617', - 'icu-regextst:618', - 'icu-regextst:619', - 'icu-regextst:620', - 'icu-regextst:621', - 'icu-regextst:622', - 'icu-regextst:623', - 'icu-regextst:624', - 'icu-regextst:625', - 'icu-regextst:1289', - 'icu-regextst:1290', - 'icu-regextst:1291', - 'icu-regextst:1292', - 'icu-regextst:1293', - 'icu-regextst:1294', - 'icu-regextst:1295', - 'icu-regextst:1296', - 'icu-regextst:1504', - 'icu-regextst:1505' - ); - } - - // 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' - ); - } - - // 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..47f9b79d0 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 @@ -10,248 +10,14 @@ class WP_MySQL_On_SQLite_Regexp_Like_Tests extends WP_MySQL_On_SQLite_Regexp_Tes protected function get_known_failures(): array { $pcre_version = explode( ' ', PCRE_VERSION )[0]; - $is_pcre2 = version_compare( $pcre_version, '10', '>=' ); // 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', - 'mysql-server-suite:12328', - 'mysql-server-suite:12329', - 'mysql-server-suite:12330', - 'mysql-server-suite:12331', - 'mysql-server-suite:12332', - 'mysql-server-suite:12333', - 'mysql-server-suite:12334', - 'mysql-server-suite:12335', - 'mysql-server-suite:12336', - 'mysql-server-suite:12337', - 'mysql-server-suite:12338', - 'mysql-server-suite:12339', - 'mysql-server-suite:12340', - 'mysql-server-suite:12341', - 'mysql-server-suite:12342', - 'mysql-server-suite:12343', - 'mysql-server-suite:12344', - 'mysql-server-suite:12345', - 'mysql-server-suite:12346', - 'mysql-server-suite:12347', - 'mysql-server-suite:12348', - 'mysql-server-suite:12349', - 'mysql-server-suite:12350', - 'mysql-server-suite:12351', - 'mysql-server-suite:12352', - 'mysql-server-suite:12353', - 'mysql-server-suite:12354', - 'mysql-server-suite:12355', - 'mysql-server-suite:12356', - 'mysql-server-suite:12357', - 'mysql-server-suite:12358', - 'mysql-server-suite:12359', - 'mysql-server-suite:12360', - 'mysql-server-suite:12361', - 'mysql-server-suite:12362', - 'mysql-server-suite:12363', - 'mysql-server-suite:12364', - 'mysql-server-suite:12365', - 'mysql-server-suite:12366', - 'mysql-server-suite:12367', - 'mysql-server-suite:12368', - 'mysql-server-suite:12369', - 'mysql-server-suite:12370', - 'mysql-server-suite:12371', - 'mysql-server-suite:12372', - 'mysql-server-suite:12373', - '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', - 'mysql-server-suite:12592', - 'mysql-server-suite:12593', - 'mysql-server-suite:12594', - 'mysql-server-suite:12595', - 'mysql-server-suite:12596', - 'mysql-server-suite:12597', - 'mysql-server-suite:12598', - 'mysql-server-suite:12599', - 'mysql-server-suite:12600', - 'mysql-server-suite:12601', - 'mysql-server-suite:12602', - 'mysql-server-suite:12603', - 'mysql-server-suite:12604', - 'mysql-server-suite:12605', - 'mysql-server-suite:12606', - 'mysql-server-suite:12607', - 'mysql-server-suite:12608', - 'mysql-server-suite:12609', - 'mysql-server-suite:12610', - 'mysql-server-suite:12611', - 'mysql-server-suite:12612', - 'icu-regextst:133', - 'icu-regextst:134', - 'icu-regextst:135', - 'icu-regextst:136', - 'icu-regextst:146', - 'icu-regextst:147', - 'icu-regextst:148', - 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', - 'icu-regextst:219', - 'icu-regextst:220', - 'icu-regextst:221', - 'icu-regextst:222', - 'icu-regextst:223', - 'icu-regextst:224', - 'icu-regextst:227', - 'icu-regextst:228', - 'icu-regextst:229', - 'icu-regextst:230', - 'icu-regextst:231', - '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', - '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', - 'icu-regextst:523', + // MySQL reports a duplicate capture name as 3887. The driver reports a syntax error (3688). 'icu-regextst:524', 'icu-regextst:525', + + // PCRE case folding cannot match one character against several, such as "ß" against "ss". 'icu-regextst:538', 'icu-regextst:539', 'icu-regextst:540', @@ -262,196 +28,6 @@ protected function get_known_failures(): array { 'icu-regextst:545', 'icu-regextst:546', 'icu-regextst:547', - 'icu-regextst:564', - 'icu-regextst:565', - 'icu-regextst:566', - 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', - 'icu-regextst:590', - 'icu-regextst:591', - 'icu-regextst:626', - 'icu-regextst:627', - 'icu-regextst:628', - 'icu-regextst:629', - 'icu-regextst:630', - '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', - 'icu-regextst:726', - 'icu-regextst:727', - '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', - 'icu-regextst:942', - 'icu-regextst:949', - 'icu-regextst:950', - 'icu-regextst:951', - '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', - 'icu-regextst:1058', - 'icu-regextst:1065', - 'icu-regextst:1066', - 'icu-regextst:1081', - 'icu-regextst:1082', - 'icu-regextst:1083', - 'icu-regextst:1084', - 'icu-regextst:1085', - 'icu-regextst:1086', - 'icu-regextst:1087', - 'icu-regextst:1088', - 'icu-regextst:1089', - 'icu-regextst:1090', - 'icu-regextst:1091', - 'icu-regextst:1092', - 'icu-regextst:1093', - 'icu-regextst:1094', - 'icu-regextst:1095', - 'icu-regextst:1096', - 'icu-regextst:1097', - 'icu-regextst:1098', - 'icu-regextst:1099', - 'icu-regextst:1100', - 'icu-regextst:1101', - 'icu-regextst:1102', - 'icu-regextst:1103', - 'icu-regextst:1104', - 'icu-regextst:1105', - 'icu-regextst:1106', - 'icu-regextst:1107', - 'icu-regextst:1108', - 'icu-regextst:1109', - 'icu-regextst:1110', - 'icu-regextst:1111', - 'icu-regextst:1112', - 'icu-regextst:1113', - 'icu-regextst:1114', - 'icu-regextst:1115', - 'icu-regextst:1116', - 'icu-regextst:1117', - 'icu-regextst:1118', - 'icu-regextst:1119', - 'icu-regextst:1120', - 'icu-regextst:1121', - 'icu-regextst:1122', - 'icu-regextst:1123', - 'icu-regextst:1124', - 'icu-regextst:1125', - 'icu-regextst:1126', - 'icu-regextst:1127', - 'icu-regextst:1128', - 'icu-regextst:1129', - 'icu-regextst:1130', - 'icu-regextst:1131', - 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', - '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', - 'icu-regextst:1180', - 'icu-regextst:1181', - 'icu-regextst:1182', - 'icu-regextst:1185', - 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -464,8 +40,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', @@ -478,335 +52,34 @@ protected function get_known_failures(): array { 'icu-regextst:1260', 'icu-regextst:1263', 'icu-regextst:1264', - 'icu-regextst:1301', - 'icu-regextst:1302', - 'icu-regextst:1318', - 'icu-regextst:1319', - 'icu-regextst:1330', - 'icu-regextst:1331', - 'icu-regextst:1332', - 'icu-regextst:1333', - 'icu-regextst:1334', - 'icu-regextst:1335', - 'icu-regextst:1336', - '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', - '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 accepts UTF-16 surrogate escapes. The translation emits each surrogate separately, which PCRE rejects. + 'icu-regextst:715', + 'icu-regextst:716', + 'icu-regextst:717', + 'icu-regextst:718', + 'icu-regextst:719', + 'icu-regextst:720', + + // The translator reads names such as Inbasiclatin and Letter as scripts, which PCRE rejects (3688). + 'icu-regextst:1093', + 'icu-regextst:1094', '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', - 'icu-regextst:1425', - 'icu-regextst:1426', - 'icu-regextst:1427', - 'icu-regextst:1428', - 'icu-regextst:1429', - 'icu-regextst:1430', - 'icu-regextst:1431', - 'icu-regextst:1432', - 'icu-regextst:1433', 'icu-regextst:1434', 'icu-regextst:1435', - 'icu-regextst:1436', - 'icu-regextst:1437', - 'icu-regextst:1438', - 'icu-regextst:1439', - 'icu-regextst:1440', - 'icu-regextst:1441', - 'icu-regextst:1442', - 'icu-regextst:1443', - 'icu-regextst:1444', - 'icu-regextst:1445', - 'icu-regextst:1446', - 'icu-regextst:1447', + + // MySQL reports error 4007 for oversized repetition counts and 3685 for the property names In and Is. + 'icu-regextst:1334', + 'icu-regextst:1335', + 'icu-regextst:1336', + 'icu-regextst:1337', 'icu-regextst:1448', 'icu-regextst:1449', 'icu-regextst:1450', 'icu-regextst:1451', - 'icu-regextst:1454', - 'icu-regextst:1455', - 'icu-regextst:1456', - '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', ); - // 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( - $failures, - 'icu-regextst:45', - 'icu-regextst:46', - 'icu-regextst:1496', - 'icu-regextst:1497' - ); - } - // Before PCRE2 10.35, a repeated group with a back reference to itself, like "^(a\1?){4}$", was atomic. if ( version_compare( $pcre_version, '10.35', '<' ) ) { array_push( @@ -816,146 +89,6 @@ protected function get_known_failures(): array { ); } - // Binary Unicode properties, like \p{Alphabetic}, arrived in PCRE2 10.40. - if ( version_compare( $pcre_version, '10.40', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:12377', - 'mysql-server-suite:12378', - 'mysql-server-suite:12379', - 'mysql-server-suite:12380', - 'mysql-server-suite:12381', - 'mysql-server-suite:12382', - 'mysql-server-suite:12383', - 'mysql-server-suite:12384', - 'mysql-server-suite:12385', - 'mysql-server-suite:12386', - 'mysql-server-suite:12387', - 'mysql-server-suite:12388', - 'mysql-server-suite:12389', - 'mysql-server-suite:12390', - 'mysql-server-suite:12391', - 'mysql-server-suite:12392', - 'mysql-server-suite:12393', - 'mysql-server-suite:12394', - 'mysql-server-suite:12395', - 'mysql-server-suite:12396', - 'mysql-server-suite:12397', - 'mysql-server-suite:12398', - 'mysql-server-suite:12399', - 'mysql-server-suite:12400', - 'mysql-server-suite:12401', - 'mysql-server-suite:12402', - 'mysql-server-suite:12403', - 'mysql-server-suite:12404', - 'mysql-server-suite:12405', - 'mysql-server-suite:12406', - 'mysql-server-suite:12407', - 'mysql-server-suite:12408', - 'mysql-server-suite:12409', - 'mysql-server-suite:12410', - 'mysql-server-suite:12411', - 'mysql-server-suite:12412', - 'mysql-server-suite:12413', - 'mysql-server-suite:12414', - 'mysql-server-suite:12415', - 'mysql-server-suite:12416', - 'mysql-server-suite:12417', - 'mysql-server-suite:12418', - 'mysql-server-suite:12419', - 'mysql-server-suite:12420', - 'mysql-server-suite:12421', - 'mysql-server-suite:12422', - 'mysql-server-suite:12423', - 'mysql-server-suite:12424', - 'mysql-server-suite:12425', - 'mysql-server-suite:12426', - 'mysql-server-suite:12427', - 'mysql-server-suite:12428', - 'mysql-server-suite:12429', - 'mysql-server-suite:12430', - 'mysql-server-suite:12431', - 'mysql-server-suite:12432', - 'mysql-server-suite:12433', - 'mysql-server-suite:12434', - 'mysql-server-suite:12435', - 'mysql-server-suite:12436', - 'mysql-server-suite:12437', - 'mysql-server-suite:12438', - 'mysql-server-suite:12439', - 'mysql-server-suite:12440', - 'mysql-server-suite:12441', - 'mysql-server-suite:12442', - 'mysql-server-suite:12443', - 'mysql-server-suite:12444', - 'mysql-server-suite:12445', - 'mysql-server-suite:12446', - 'mysql-server-suite:12447', - 'mysql-server-suite:12448', - 'mysql-server-suite:12449', - 'mysql-server-suite:12450', - 'mysql-server-suite:12451', - 'mysql-server-suite:12452', - 'mysql-server-suite:12453', - 'mysql-server-suite:12454', - 'icu-regextst:1452', - 'icu-regextst:1453' - ); - } - - // Lookbehinds of variable length, like "(?<=bc?c?c?)", arrived in PCRE2 10.43. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'icu-regextst:612', - 'icu-regextst:613', - 'icu-regextst:614', - 'icu-regextst:615', - 'icu-regextst:616', - 'icu-regextst:617', - 'icu-regextst:618', - 'icu-regextst:619', - 'icu-regextst:620', - 'icu-regextst:621', - 'icu-regextst:622', - 'icu-regextst:623', - 'icu-regextst:624', - 'icu-regextst:625', - 'icu-regextst:1289', - 'icu-regextst:1290', - 'icu-regextst:1291', - 'icu-regextst:1292', - 'icu-regextst:1293', - 'icu-regextst:1294', - 'icu-regextst:1295', - 'icu-regextst:1296', - 'icu-regextst:1504', - 'icu-regextst:1505' - ); - } - - // 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' - ); - } - - // 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..896024a58 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,264 +14,19 @@ 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: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', - 'mysql-server-suite:12328', - 'mysql-server-suite:12329', - 'mysql-server-suite:12330', - 'mysql-server-suite:12331', - 'mysql-server-suite:12332', - 'mysql-server-suite:12333', - 'mysql-server-suite:12334', - 'mysql-server-suite:12335', - 'mysql-server-suite:12336', - 'mysql-server-suite:12337', - 'mysql-server-suite:12338', - 'mysql-server-suite:12339', - 'mysql-server-suite:12340', - 'mysql-server-suite:12341', - 'mysql-server-suite:12342', - 'mysql-server-suite:12343', - 'mysql-server-suite:12344', - 'mysql-server-suite:12345', - 'mysql-server-suite:12346', - 'mysql-server-suite:12347', - 'mysql-server-suite:12348', - 'mysql-server-suite:12349', - 'mysql-server-suite:12350', - 'mysql-server-suite:12351', - 'mysql-server-suite:12352', - 'mysql-server-suite:12353', - 'mysql-server-suite:12354', - 'mysql-server-suite:12355', - 'mysql-server-suite:12356', - 'mysql-server-suite:12357', - 'mysql-server-suite:12358', - 'mysql-server-suite:12359', - 'mysql-server-suite:12360', - 'mysql-server-suite:12361', - 'mysql-server-suite:12362', - 'mysql-server-suite:12363', - 'mysql-server-suite:12364', - 'mysql-server-suite:12365', - 'mysql-server-suite:12366', - 'mysql-server-suite:12367', - 'mysql-server-suite:12368', - 'mysql-server-suite:12369', - 'mysql-server-suite:12370', - 'mysql-server-suite:12371', - 'mysql-server-suite:12372', - 'mysql-server-suite:12373', - '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', + // PCRE and ICU split "स्ते" into different grapheme clusters (\X). 'mysql-server-suite:12579', 'mysql-server-suite:12580', - 'mysql-server-suite:12589', - 'mysql-server-suite:12590', - 'mysql-server-suite:12591', - 'mysql-server-suite:12592', - 'mysql-server-suite:12593', - 'mysql-server-suite:12594', - 'mysql-server-suite:12595', - 'mysql-server-suite:12596', - 'mysql-server-suite:12597', - 'mysql-server-suite:12598', - 'mysql-server-suite:12599', - 'mysql-server-suite:12600', - 'mysql-server-suite:12601', - 'mysql-server-suite:12602', - 'mysql-server-suite:12603', - 'mysql-server-suite:12604', - 'mysql-server-suite:12605', - 'mysql-server-suite:12606', - 'mysql-server-suite:12607', - 'mysql-server-suite:12608', - 'mysql-server-suite:12609', - 'mysql-server-suite:12610', - 'mysql-server-suite:12611', - 'mysql-server-suite:12612', - 'icu-regextst:133', - 'icu-regextst:134', - 'icu-regextst:135', - 'icu-regextst:136', - 'icu-regextst:146', - 'icu-regextst:147', - 'icu-regextst:148', - 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', + + // ICU word boundaries skip combining marks. The translated \b tests the adjacent characters. 'icu-regextst:217', 'icu-regextst:218', - 'icu-regextst:219', - 'icu-regextst:220', - 'icu-regextst:221', - 'icu-regextst:222', - 'icu-regextst:223', - 'icu-regextst:224', - 'icu-regextst:227', - 'icu-regextst:228', - 'icu-regextst:229', - 'icu-regextst:230', - 'icu-regextst:231', - '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', - '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', - 'icu-regextst:523', + + // MySQL reports a duplicate capture name as 3887. The driver reports a syntax error (3688). 'icu-regextst:524', 'icu-regextst:525', + + // PCRE case folding cannot match one character against several, such as "ß" against "ss". 'icu-regextst:538', 'icu-regextst:539', 'icu-regextst:540', @@ -282,216 +37,6 @@ protected function get_known_failures(): array { 'icu-regextst:545', 'icu-regextst:546', 'icu-regextst:547', - 'icu-regextst:564', - 'icu-regextst:565', - 'icu-regextst:566', - 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', - 'icu-regextst:590', - 'icu-regextst:591', - 'icu-regextst:626', - 'icu-regextst:627', - 'icu-regextst:628', - 'icu-regextst:629', - 'icu-regextst:630', - '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', - 'icu-regextst:726', - 'icu-regextst:727', - 'icu-regextst:728', - 'icu-regextst:843', - 'icu-regextst:844', - 'icu-regextst:879', - 'icu-regextst:880', - 'icu-regextst:881', - 'icu-regextst:882', - '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', - 'icu-regextst:942', - 'icu-regextst:949', - '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:1055', - 'icu-regextst:1056', - 'icu-regextst:1057', - 'icu-regextst:1058', - 'icu-regextst:1065', - 'icu-regextst:1066', - 'icu-regextst:1081', - 'icu-regextst:1082', - 'icu-regextst:1083', - 'icu-regextst:1084', - 'icu-regextst:1085', - 'icu-regextst:1086', - 'icu-regextst:1087', - 'icu-regextst:1088', - 'icu-regextst:1089', - 'icu-regextst:1090', - 'icu-regextst:1091', - 'icu-regextst:1092', - 'icu-regextst:1093', - 'icu-regextst:1094', - 'icu-regextst:1095', - 'icu-regextst:1096', - 'icu-regextst:1097', - 'icu-regextst:1098', - 'icu-regextst:1099', - 'icu-regextst:1100', - 'icu-regextst:1101', - 'icu-regextst:1102', - 'icu-regextst:1103', - 'icu-regextst:1104', - 'icu-regextst:1105', - 'icu-regextst:1106', - 'icu-regextst:1107', - 'icu-regextst:1108', - 'icu-regextst:1109', - 'icu-regextst:1110', - 'icu-regextst:1111', - 'icu-regextst:1112', - 'icu-regextst:1113', - 'icu-regextst:1114', - 'icu-regextst:1115', - 'icu-regextst:1116', - 'icu-regextst:1117', - 'icu-regextst:1118', - 'icu-regextst:1119', - 'icu-regextst:1120', - 'icu-regextst:1121', - 'icu-regextst:1122', - 'icu-regextst:1123', - 'icu-regextst:1124', - 'icu-regextst:1125', - 'icu-regextst:1126', - 'icu-regextst:1127', - 'icu-regextst:1128', - 'icu-regextst:1129', - 'icu-regextst:1130', - 'icu-regextst:1131', - 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', - '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', - 'icu-regextst:1171', - 'icu-regextst:1179', - 'icu-regextst:1180', - 'icu-regextst:1181', - 'icu-regextst:1182', - 'icu-regextst:1185', - 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -504,10 +49,6 @@ protected function get_known_failures(): array { 'icu-regextst:1240', 'icu-regextst:1241', 'icu-regextst:1242', - 'icu-regextst:1243', - 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -518,344 +59,53 @@ protected function get_known_failures(): array { 'icu-regextst:1256', 'icu-regextst:1259', 'icu-regextst:1260', - 'icu-regextst:1261', - '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:1318', - 'icu-regextst:1319', - 'icu-regextst:1330', - 'icu-regextst:1331', - 'icu-regextst:1332', - 'icu-regextst:1333', - 'icu-regextst:1334', - 'icu-regextst:1335', - 'icu-regextst:1336', - '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', - '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', + + // Case folding changes the matched text even though both engines find a match. + 'icu-regextst:1243', + 'icu-regextst:1244', + 'icu-regextst:1261', + 'icu-regextst:1262', + + // ICU accepts UTF-16 surrogate escapes. The translation emits each surrogate separately, which PCRE rejects. + 'icu-regextst:715', + 'icu-regextst:716', + 'icu-regextst:717', + 'icu-regextst:718', + 'icu-regextst:719', + 'icu-regextst:720', + + // With the MySQL "n" flag, ICU matches CRLF as a unit. The translated dot matches CR and LF separately. + 'icu-regextst:919', + + // The translator reads names such as Inbasiclatin and Letter as scripts, which PCRE rejects (3688). + 'icu-regextst:1093', + 'icu-regextst:1094', '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', - 'icu-regextst:1425', - 'icu-regextst:1426', - 'icu-regextst:1427', - 'icu-regextst:1428', - 'icu-regextst:1429', - 'icu-regextst:1430', - 'icu-regextst:1431', - 'icu-regextst:1432', - 'icu-regextst:1433', 'icu-regextst:1434', 'icu-regextst:1435', - 'icu-regextst:1436', - 'icu-regextst:1437', - 'icu-regextst:1438', - 'icu-regextst:1439', - 'icu-regextst:1440', - 'icu-regextst:1441', - 'icu-regextst:1442', - 'icu-regextst:1443', - 'icu-regextst:1444', - 'icu-regextst:1445', - 'icu-regextst:1446', - 'icu-regextst:1447', + + // MySQL reports error 4007 for oversized repetition counts and 3685 for the property names In and Is. + 'icu-regextst:1334', + 'icu-regextst:1335', + 'icu-regextst:1336', + 'icu-regextst:1337', 'icu-regextst:1448', 'icu-regextst:1449', 'icu-regextst:1450', 'icu-regextst:1451', - 'icu-regextst:1454', - 'icu-regextst:1455', - 'icu-regextst:1456', - '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', + + // The driver converts the invalid datetime in the subject to '0000-00-00 00:00:00'. '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', + + // The driver normalizes the subject '2002-4-30' to '2002-04-30' before matching. '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', ); - // 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( - $failures, - 'icu-regextst:45', - 'icu-regextst:46', - 'icu-regextst:1496', - 'icu-regextst:1497' - ); - } - // PCRE 8 splits some grapheme clusters for \X, like an emoji with a skin tone, which ICU and PCRE2 keep whole. if ( ! $is_pcre2 ) { array_push( @@ -878,158 +128,14 @@ protected function get_known_failures(): array { ); } - // Binary Unicode properties, like \p{Alphabetic}, arrived in PCRE2 10.40. + // The Alphabetic fallback for PCRE versions before 10.40 misses combining vowel signs such as "े". if ( version_compare( $pcre_version, '10.40', '<' ) ) { array_push( $failures, - 'mysql-server-suite:12377', - 'mysql-server-suite:12378', - 'mysql-server-suite:12379', - 'mysql-server-suite:12380', - 'mysql-server-suite:12381', - 'mysql-server-suite:12382', - 'mysql-server-suite:12383', - 'mysql-server-suite:12384', - 'mysql-server-suite:12385', - 'mysql-server-suite:12386', - 'mysql-server-suite:12387', - 'mysql-server-suite:12388', - 'mysql-server-suite:12389', - 'mysql-server-suite:12390', - 'mysql-server-suite:12391', - 'mysql-server-suite:12392', 'mysql-server-suite:12393', 'mysql-server-suite:12394', - 'mysql-server-suite:12395', - 'mysql-server-suite:12396', - 'mysql-server-suite:12397', - 'mysql-server-suite:12398', - 'mysql-server-suite:12399', - 'mysql-server-suite:12400', - 'mysql-server-suite:12401', - 'mysql-server-suite:12402', - 'mysql-server-suite:12403', - 'mysql-server-suite:12404', - 'mysql-server-suite:12405', - 'mysql-server-suite:12406', - 'mysql-server-suite:12407', - 'mysql-server-suite:12408', - 'mysql-server-suite:12409', - 'mysql-server-suite:12410', - 'mysql-server-suite:12411', - 'mysql-server-suite:12412', - 'mysql-server-suite:12413', - 'mysql-server-suite:12414', - 'mysql-server-suite:12415', - 'mysql-server-suite:12416', - 'mysql-server-suite:12417', - 'mysql-server-suite:12418', 'mysql-server-suite:12419', - 'mysql-server-suite:12420', - 'mysql-server-suite:12421', - 'mysql-server-suite:12422', - 'mysql-server-suite:12423', - 'mysql-server-suite:12424', - 'mysql-server-suite:12425', - 'mysql-server-suite:12426', - 'mysql-server-suite:12427', - 'mysql-server-suite:12428', - 'mysql-server-suite:12429', - 'mysql-server-suite:12430', - 'mysql-server-suite:12431', - 'mysql-server-suite:12432', - 'mysql-server-suite:12433', - 'mysql-server-suite:12434', - 'mysql-server-suite:12435', - 'mysql-server-suite:12436', - 'mysql-server-suite:12437', - 'mysql-server-suite:12438', - 'mysql-server-suite:12439', - 'mysql-server-suite:12440', - 'mysql-server-suite:12441', - 'mysql-server-suite:12442', - 'mysql-server-suite:12443', - 'mysql-server-suite:12444', - 'mysql-server-suite:12445', - 'mysql-server-suite:12446', - 'mysql-server-suite:12447', - 'mysql-server-suite:12448', - 'mysql-server-suite:12449', - 'mysql-server-suite:12450', - 'mysql-server-suite:12451', - 'mysql-server-suite:12452', - 'mysql-server-suite:12453', - 'mysql-server-suite:12454', - 'icu-regextst:1452', - 'icu-regextst:1453' - ); - } - - // Lookbehinds of variable length, like "(?<=bc?c?c?)", arrived in PCRE2 10.43. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'icu-regextst:612', - 'icu-regextst:613', - 'icu-regextst:614', - 'icu-regextst:615', - 'icu-regextst:616', - 'icu-regextst:617', - 'icu-regextst:618', - 'icu-regextst:619', - 'icu-regextst:620', - 'icu-regextst:621', - 'icu-regextst:622', - 'icu-regextst:623', - 'icu-regextst:624', - 'icu-regextst:625', - 'icu-regextst:1289', - 'icu-regextst:1290', - 'icu-regextst:1291', - 'icu-regextst:1292', - 'icu-regextst:1293', - 'icu-regextst:1294', - 'icu-regextst:1295', - 'icu-regextst:1296', - 'icu-regextst:1504', - 'icu-regextst:1505' - ); - } - - // 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' - ); - } - - // 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' + 'mysql-server-suite:12420' ); } 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..b3de370d7 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,250 +14,11 @@ 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: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', - 'mysql-server-suite:12328', - 'mysql-server-suite:12329', - 'mysql-server-suite:12330', - 'mysql-server-suite:12331', - 'mysql-server-suite:12332', - 'mysql-server-suite:12333', - 'mysql-server-suite:12334', - 'mysql-server-suite:12335', - 'mysql-server-suite:12336', - 'mysql-server-suite:12337', - 'mysql-server-suite:12338', - 'mysql-server-suite:12339', - 'mysql-server-suite:12340', - 'mysql-server-suite:12341', - 'mysql-server-suite:12342', - 'mysql-server-suite:12343', - 'mysql-server-suite:12344', - 'mysql-server-suite:12345', - 'mysql-server-suite:12346', - 'mysql-server-suite:12347', - 'mysql-server-suite:12348', - 'mysql-server-suite:12349', - 'mysql-server-suite:12350', - 'mysql-server-suite:12351', - 'mysql-server-suite:12352', - 'mysql-server-suite:12353', - 'mysql-server-suite:12354', - 'mysql-server-suite:12355', - 'mysql-server-suite:12356', - 'mysql-server-suite:12357', - 'mysql-server-suite:12358', - 'mysql-server-suite:12359', - 'mysql-server-suite:12360', - 'mysql-server-suite:12361', - 'mysql-server-suite:12362', - 'mysql-server-suite:12363', - 'mysql-server-suite:12364', - 'mysql-server-suite:12365', - 'mysql-server-suite:12366', - 'mysql-server-suite:12367', - 'mysql-server-suite:12368', - 'mysql-server-suite:12369', - 'mysql-server-suite:12370', - 'mysql-server-suite:12371', - 'mysql-server-suite:12372', - 'mysql-server-suite:12373', - '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', - 'mysql-server-suite:12592', - 'mysql-server-suite:12593', - 'mysql-server-suite:12594', - 'mysql-server-suite:12595', - 'mysql-server-suite:12596', - 'mysql-server-suite:12597', - 'mysql-server-suite:12598', - 'mysql-server-suite:12599', - 'mysql-server-suite:12600', - 'mysql-server-suite:12601', - 'mysql-server-suite:12602', - 'mysql-server-suite:12603', - 'mysql-server-suite:12604', - 'mysql-server-suite:12605', - 'mysql-server-suite:12606', - 'mysql-server-suite:12607', - 'mysql-server-suite:12608', - 'mysql-server-suite:12609', - 'mysql-server-suite:12610', - 'mysql-server-suite:12611', - 'mysql-server-suite:12612', - 'icu-regextst:133', - 'icu-regextst:134', - 'icu-regextst:135', - 'icu-regextst:136', - 'icu-regextst:146', - 'icu-regextst:147', - 'icu-regextst:148', - 'icu-regextst:149', - 'icu-regextst:165', - 'icu-regextst:166', - 'icu-regextst:209', - 'icu-regextst:210', - 'icu-regextst:219', - 'icu-regextst:220', - 'icu-regextst:221', - 'icu-regextst:222', - 'icu-regextst:223', - 'icu-regextst:224', - 'icu-regextst:227', - 'icu-regextst:228', - 'icu-regextst:229', - 'icu-regextst:230', - 'icu-regextst:231', - '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', - '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', - 'icu-regextst:523', + // MySQL reports a duplicate capture name as 3887. The driver reports a syntax error (3688). 'icu-regextst:524', 'icu-regextst:525', + + // PCRE case folding cannot match one character against several, such as "ß" against "ss". 'icu-regextst:538', 'icu-regextst:539', 'icu-regextst:540', @@ -268,207 +29,6 @@ protected function get_known_failures(): array { 'icu-regextst:545', 'icu-regextst:546', 'icu-regextst:547', - 'icu-regextst:564', - 'icu-regextst:565', - 'icu-regextst:566', - 'icu-regextst:567', - 'icu-regextst:580', - 'icu-regextst:581', - 'icu-regextst:582', - 'icu-regextst:583', - 'icu-regextst:584', - 'icu-regextst:585', - 'icu-regextst:590', - 'icu-regextst:591', - 'icu-regextst:626', - 'icu-regextst:627', - 'icu-regextst:628', - 'icu-regextst:629', - 'icu-regextst:630', - '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', - 'icu-regextst:726', - 'icu-regextst:727', - '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', - 'icu-regextst:942', - 'icu-regextst:949', - '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:1055', - 'icu-regextst:1056', - 'icu-regextst:1057', - 'icu-regextst:1058', - 'icu-regextst:1065', - 'icu-regextst:1066', - 'icu-regextst:1081', - 'icu-regextst:1082', - 'icu-regextst:1083', - 'icu-regextst:1084', - 'icu-regextst:1085', - 'icu-regextst:1086', - 'icu-regextst:1087', - 'icu-regextst:1088', - 'icu-regextst:1089', - 'icu-regextst:1090', - 'icu-regextst:1091', - 'icu-regextst:1092', - 'icu-regextst:1093', - 'icu-regextst:1094', - 'icu-regextst:1095', - 'icu-regextst:1096', - 'icu-regextst:1097', - 'icu-regextst:1098', - 'icu-regextst:1099', - 'icu-regextst:1100', - 'icu-regextst:1101', - 'icu-regextst:1102', - 'icu-regextst:1103', - 'icu-regextst:1104', - 'icu-regextst:1105', - 'icu-regextst:1106', - 'icu-regextst:1107', - 'icu-regextst:1108', - 'icu-regextst:1109', - 'icu-regextst:1110', - 'icu-regextst:1111', - 'icu-regextst:1112', - 'icu-regextst:1113', - 'icu-regextst:1114', - 'icu-regextst:1115', - 'icu-regextst:1116', - 'icu-regextst:1117', - 'icu-regextst:1118', - 'icu-regextst:1119', - 'icu-regextst:1120', - 'icu-regextst:1121', - 'icu-regextst:1122', - 'icu-regextst:1123', - 'icu-regextst:1124', - 'icu-regextst:1125', - 'icu-regextst:1126', - 'icu-regextst:1127', - 'icu-regextst:1128', - 'icu-regextst:1129', - 'icu-regextst:1130', - 'icu-regextst:1131', - 'icu-regextst:1132', - 'icu-regextst:1133', - 'icu-regextst:1134', - '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', - 'icu-regextst:1180', - 'icu-regextst:1181', - 'icu-regextst:1182', - 'icu-regextst:1185', - 'icu-regextst:1186', - 'icu-regextst:1199', - 'icu-regextst:1200', 'icu-regextst:1221', 'icu-regextst:1222', 'icu-regextst:1225', @@ -481,10 +41,6 @@ protected function get_known_failures(): array { 'icu-regextst:1240', 'icu-regextst:1241', 'icu-regextst:1242', - 'icu-regextst:1243', - 'icu-regextst:1244', - 'icu-regextst:1247', - 'icu-regextst:1248', 'icu-regextst:1249', 'icu-regextst:1250', 'icu-regextst:1251', @@ -495,342 +51,46 @@ protected function get_known_failures(): array { 'icu-regextst:1256', 'icu-regextst:1259', 'icu-regextst:1260', - 'icu-regextst:1261', - '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:1318', - 'icu-regextst:1319', - 'icu-regextst:1330', - 'icu-regextst:1331', - 'icu-regextst:1332', - 'icu-regextst:1333', - 'icu-regextst:1334', - 'icu-regextst:1335', - 'icu-regextst:1336', - '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', - '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', + + // Case folding changes the matched text even though both engines find a match. + 'icu-regextst:1243', + 'icu-regextst:1244', + 'icu-regextst:1261', + 'icu-regextst:1262', + + // ICU accepts UTF-16 surrogate escapes. The translation emits each surrogate separately, which PCRE rejects. + 'icu-regextst:715', + 'icu-regextst:716', + 'icu-regextst:717', + 'icu-regextst:718', + 'icu-regextst:719', + 'icu-regextst:720', + + // The translator reads names such as Inbasiclatin and Letter as scripts, which PCRE rejects (3688). + 'icu-regextst:1093', + 'icu-regextst:1094', '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', - 'icu-regextst:1425', - 'icu-regextst:1426', - 'icu-regextst:1427', - 'icu-regextst:1428', - 'icu-regextst:1429', - 'icu-regextst:1430', - 'icu-regextst:1431', - 'icu-regextst:1432', - 'icu-regextst:1433', 'icu-regextst:1434', 'icu-regextst:1435', - 'icu-regextst:1436', - 'icu-regextst:1437', - 'icu-regextst:1438', - 'icu-regextst:1439', - 'icu-regextst:1440', - 'icu-regextst:1441', - 'icu-regextst:1442', - 'icu-regextst:1443', - 'icu-regextst:1444', - 'icu-regextst:1445', - 'icu-regextst:1446', - 'icu-regextst:1447', + + // MySQL reports error 4007 for oversized repetition counts and 3685 for the property names In and Is. + 'icu-regextst:1334', + 'icu-regextst:1335', + 'icu-regextst:1336', + 'icu-regextst:1337', 'icu-regextst:1448', 'icu-regextst:1449', 'icu-regextst:1450', 'icu-regextst:1451', - 'icu-regextst:1454', - 'icu-regextst:1455', - 'icu-regextst:1456', - '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', + + // The driver normalizes the subject '2002-4-30' to '2002-04-30' before matching. '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', ); - // 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( - $failures, - 'icu-regextst:45', - 'icu-regextst:46', - 'icu-regextst:1496', - 'icu-regextst:1497' - ); - } - // PCRE 8 splits some grapheme clusters for \X, like an emoji with a skin tone, which ICU and PCRE2 keep whole. if ( ! $is_pcre2 ) { array_push( @@ -849,157 +109,6 @@ protected function get_known_failures(): array { ); } - // Binary Unicode properties, like \p{Alphabetic}, arrived in PCRE2 10.40. - if ( version_compare( $pcre_version, '10.40', '<' ) ) { - array_push( - $failures, - 'mysql-server-suite:12377', - 'mysql-server-suite:12378', - 'mysql-server-suite:12379', - 'mysql-server-suite:12380', - 'mysql-server-suite:12381', - 'mysql-server-suite:12382', - 'mysql-server-suite:12383', - 'mysql-server-suite:12384', - 'mysql-server-suite:12385', - 'mysql-server-suite:12386', - 'mysql-server-suite:12387', - 'mysql-server-suite:12388', - 'mysql-server-suite:12389', - 'mysql-server-suite:12390', - 'mysql-server-suite:12391', - 'mysql-server-suite:12392', - 'mysql-server-suite:12393', - 'mysql-server-suite:12394', - 'mysql-server-suite:12395', - 'mysql-server-suite:12396', - 'mysql-server-suite:12397', - 'mysql-server-suite:12398', - 'mysql-server-suite:12399', - 'mysql-server-suite:12400', - 'mysql-server-suite:12401', - 'mysql-server-suite:12402', - 'mysql-server-suite:12403', - 'mysql-server-suite:12404', - 'mysql-server-suite:12405', - 'mysql-server-suite:12406', - 'mysql-server-suite:12407', - 'mysql-server-suite:12408', - 'mysql-server-suite:12409', - 'mysql-server-suite:12410', - 'mysql-server-suite:12411', - 'mysql-server-suite:12412', - 'mysql-server-suite:12413', - 'mysql-server-suite:12414', - 'mysql-server-suite:12415', - 'mysql-server-suite:12416', - 'mysql-server-suite:12417', - 'mysql-server-suite:12418', - 'mysql-server-suite:12419', - 'mysql-server-suite:12420', - 'mysql-server-suite:12421', - 'mysql-server-suite:12422', - 'mysql-server-suite:12423', - 'mysql-server-suite:12424', - 'mysql-server-suite:12425', - 'mysql-server-suite:12426', - 'mysql-server-suite:12427', - 'mysql-server-suite:12428', - 'mysql-server-suite:12429', - 'mysql-server-suite:12430', - 'mysql-server-suite:12431', - 'mysql-server-suite:12432', - 'mysql-server-suite:12433', - 'mysql-server-suite:12434', - 'mysql-server-suite:12435', - 'mysql-server-suite:12436', - 'mysql-server-suite:12437', - 'mysql-server-suite:12438', - 'mysql-server-suite:12439', - 'mysql-server-suite:12440', - 'mysql-server-suite:12441', - 'mysql-server-suite:12442', - 'mysql-server-suite:12443', - 'mysql-server-suite:12444', - 'mysql-server-suite:12445', - 'mysql-server-suite:12446', - 'mysql-server-suite:12447', - 'mysql-server-suite:12448', - 'mysql-server-suite:12449', - 'mysql-server-suite:12450', - 'mysql-server-suite:12451', - 'mysql-server-suite:12452', - 'mysql-server-suite:12453', - 'mysql-server-suite:12454', - 'icu-regextst:1452', - 'icu-regextst:1453' - ); - } - - // Lookbehinds of variable length, like "(?<=bc?c?c?)", arrived in PCRE2 10.43. - if ( version_compare( $pcre_version, '10.43', '<' ) ) { - array_push( - $failures, - 'icu-regextst:612', - 'icu-regextst:613', - 'icu-regextst:614', - 'icu-regextst:615', - 'icu-regextst:616', - 'icu-regextst:617', - 'icu-regextst:618', - 'icu-regextst:619', - 'icu-regextst:620', - 'icu-regextst:621', - 'icu-regextst:622', - 'icu-regextst:623', - 'icu-regextst:624', - 'icu-regextst:625', - 'icu-regextst:1289', - 'icu-regextst:1290', - 'icu-regextst:1291', - 'icu-regextst:1292', - 'icu-regextst:1293', - 'icu-regextst:1294', - 'icu-regextst:1295', - 'icu-regextst:1296', - 'icu-regextst:1504', - 'icu-regextst:1505' - ); - } - - // 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' - ); - } - - // 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_Test_Case.php b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Test_Case.php index 8934a90f4..463933835 100644 --- a/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Test_Case.php +++ b/packages/mysql-on-sqlite/tests/regexp/WP_MySQL_On_SQLite_Regexp_Test_Case.php @@ -24,6 +24,9 @@ * any check of the test class fails. A test class lists the cases that are expected to * fail in get_known_failures(), with version checks for the cases that fail only with * some PHP or PCRE versions. + * + * For case IDs listed in data/unsupported.json, require error 3690 and the + * recorded message in place of the MySQL result. */ abstract class WP_MySQL_On_SQLite_Regexp_Test_Case extends TestCase { const DATA_DIR = __DIR__ . '/data'; @@ -124,29 +127,32 @@ public static function get_template( int $groups ): string { * @return string[] A description of each failing case, keyed by ":". */ protected static function run_checks( string $source, array $checks ): array { - $driver = new WP_MySQL_On_SQLite( + $driver = new WP_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp', null, null, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); - $failures = array(); + $failures = array(); + $unsupported = self::read_unsupported_cases( $source ); foreach ( self::read_cases( $source ) as $case ) { $differences = array(); foreach ( $checks as $check ) { - $query = self::build_query( + $query = self::build_query( $check, $driver->quote( $case['subject'] ), $driver->quote( $case['pattern'] ), $driver->quote( self::get_template( $case['groups'] ) ), $case['match_type'] ); - $actual = self::run_query( $driver, $query ); - if ( ! self::is_same_result( $case[ $check ], $actual ) ) { + $actual = self::run_query( $driver, $query ); + $expected = $unsupported[ $case['id'] ] ?? $case[ $check ]; + $is_same = isset( $unsupported[ $case['id'] ] ) ? $expected === $actual : self::is_same_result( $expected, $actual ); + if ( ! $is_same ) { $differences[] = sprintf( '%s, expected %s, got %s', $query, - self::format_result( $case[ $check ] ), + self::format_result( $expected ), self::format_result( $actual ) ); } @@ -186,6 +192,27 @@ function ( $key ) use ( $prefix ) { ); } + /** + * Expand the inclusive case ID ranges from data/unsupported.json. + * + * @return array[] Expected errors keyed by case ID. + */ + private static function read_unsupported_cases( string $source ): array { + $ranges = json_decode( file_get_contents( self::DATA_DIR . '/unsupported.json' ), true ); + $errors = array(); + foreach ( $ranges[ $source ] as list( $first, $last, $message ) ) { + $errors += array_fill( + $first, + $last - $first + 1, + array( + 'error' => 3690, + 'message' => $message, + ) + ); + } + return $errors; + } + /** * Run a query and get its single value, its error, or the PHP errors that it caused. * @@ -210,7 +237,7 @@ function ( $severity, $message ) use ( &$php_errors ) { } catch ( PDOException $e ) { $result = array( 'error' => $e->errorInfo[1] ?? null, - 'message' => $e->getMessage(), + 'message' => $e->errorInfo[2] ?? $e->getMessage(), ); } catch ( Throwable $e ) { $php_errors[] = get_class( $e ) . ': ' . $e->getMessage(); diff --git a/packages/mysql-on-sqlite/tests/regexp/data/unsupported.json b/packages/mysql-on-sqlite/tests/regexp/data/unsupported.json new file mode 100644 index 000000000..35ecc40aa --- /dev/null +++ b/packages/mysql-on-sqlite/tests/regexp/data/unsupported.json @@ -0,0 +1,119 @@ +{ + "mysql-server-suite": [ + [1707,1734,"Unsupported regular expression syntax: a negated class in a set"], + [2977,3002,"Unsupported regular expression syntax: \\10"], + [5553,5578,"Unsupported regular expression syntax: \\10"], + [7329,7354,"Unsupported regular expression syntax: {"], + [7355,7380,"Unsupported regular expression syntax: (?x"], + [7433,7484,"Unsupported regular expression syntax: (? Date: Tue, 24 Nov 2026 13:41:55 +0100 Subject: [PATCH 5/5] Shorten a word boundary next to a word character MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A "\b" becomes a condition with three word classes, because PCRE has other word characters than ICU. Next to a literal ASCII letter, digit, or "_" that is not repeated, one side of the boundary is known, so one class is enough: "\bword\b" is now "(?]:\]\]|[|^$]|(' . self::OTHER . ')/'; + private const TOKEN = '/(?:(?:[^\\\\\[(){}|^$.*+?\/\x00]++|' . self::QUOTE . '(?:\\\\E|\z)|' . self::ESCAPE . '|' . self::POSIX . '|' . self::SET . '|[.)\/\x00])' . self::QUANTIFIER . '|' . self::LOOK_BEHIND . '|' . self::GROUP . '|' . self::BRACE . '|\[\[:[<>]:\]\]|[|^$]|(' . self::OTHER . '))(?=([A-Za-z0-9_](?![*+?{]))?)/'; // Capture groups in TOKEN. private const CAPTURE_QUANTIFIER = 1; @@ -131,6 +131,7 @@ class WP_ICU_Regex_Translator { private const CAPTURE_FLAGS_OFF = 3; private const CAPTURE_FLAG_DELIMITER = 4; private const CAPTURE_UNSUPPORTED = 5; + private const CAPTURE_NEXT_WORD = 6; // Cap the input size before expanding tokens such as word boundaries into longer PCRE patterns. private const MAX_LENGTH = 65535; @@ -173,6 +174,13 @@ class WP_ICU_Regex_Translator { */ private $is_leading = true; + /** + * Whether the previous token ended with an unquantified ASCII word character. + * + * @var bool + */ + private $is_after_word = false; + /** * Whether \G in the input pattern must fail. * @@ -228,16 +236,24 @@ private function translate_token( $parts ) { $token = $parts[0]; $quantifier = $parts[ self::CAPTURE_QUANTIFIER ] ?? ''; $item = substr( $token, 0, strlen( $token ) - strlen( $quantifier ) ); - if ( isset( $parts[ self::CAPTURE_UNSUPPORTED ] ) ) { + if ( '' !== ( $parts[ self::CAPTURE_UNSUPPORTED ] ?? '' ) ) { throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: $token", self::UNSUPPORTED ); } - $is_leading = $this->is_leading; - $this->is_leading = '|' === $token && ! $this->groups; + $is_leading = $this->is_leading; + $this->is_leading = '|' === $token && ! $this->groups; + $is_after_word = $this->is_after_word; + $this->is_after_word = false; switch ( $item[0] ) { case '\\': // A position, like "\b", can't be repeated. if ( '' === $quantifier || false === strpos( 'AbBGzZ', $item[1] ) ) { + // In "\bword\b", each boundary needs to test only the side facing away from the word. + // Omitting the other tests keeps word lists smaller when PCRE compiles them. + $is_before_word = isset( $parts[ self::CAPTURE_NEXT_WORD ] ); + if ( 'b' === strtolower( $item[1] ) && ! $this->bytes && ( $is_before_word || $is_after_word ) ) { + return '(?' . ( $is_before_word ? '<' : '' ) . ( 'b' === $item[1] ? '!' : '=' ) . '[' . self::WORD . '])'; + } return $this->translate_escape( substr( $item, 1 ), false ) . $quantifier; } break; @@ -265,8 +281,9 @@ private function translate_token( $parts ) { return '(?#)'; } // LOOK_BEHIND excludes nested groups. Translate its contents with the current flags. - $inside = self::replace( self::TOKEN, array( $this, 'translate_token' ), substr( $item, 4, -1 ) ); - $this->is_leading = false; + $inside = self::replace( self::TOKEN, array( $this, 'translate_token' ), substr( $item, 4, -1 ) ); + $this->is_leading = false; + $this->is_after_word = false; return substr( $item, 0, 4 ) . $inside . ')'; } // A lookahead consumes no text. An atomic group keeps its first match. @@ -320,6 +337,7 @@ private function translate_token( $parts ) { case '|': return '|'; default: + $this->is_after_word = '' === $quantifier && 1 === preg_match( '/[A-Za-z0-9_]$/D', $token ); return $token; } throw new WP_ICU_Regex_Exception( "Unsupported regular expression syntax: $token", self::UNSUPPORTED ); diff --git a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php index 06d2c2749..ae7c72b41 100644 --- a/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php +++ b/packages/mysql-on-sqlite/tests/icu/WP_ICU_Regex_Translator_Tests.php @@ -1050,6 +1050,24 @@ public function test_a_leading_dot_star_matches_like_any_other(): void { $this->assertSame( '/(?:\G|(?<=[\n\x0B\f\r]))[^\n\x0B\f\r]*a/X', WP_ICU_Regex_Translator::translate( '.*a', '', false, true ) ); } + public function test_a_word_boundary_next_to_a_word_character_checks_one_side(): void { + $word = '[\p{L}\p{M}\p{Nd}\p{Nl}\p{Pc}\x{200C}\x{200D}\x{24B6}-\x{24E9}\x{1F130}-\x{1F149}\x{1F150}-\x{1F169}\x{1F170}-\x{1F189}]'; + $this->assertSame( "/(?assertSame( "/(?<=$word)_1(?=$word)/uX", WP_ICU_Regex_Translator::translate( '\B_1\B' ) ); + $this->assertSame( "/a(?assertSame( '/\bword\b/X', WP_ICU_Regex_Translator::translate( '\bword\b', '', false, true ) ); + + // Keep the full boundary check unless the translator recognizes an adjacent, unquantified ASCII word character. + foreach ( array( '\b', '\b-', '\bé', '\ba*', '\ba?', '\ba{2}', '\b(a)', '\b[a]', '\b\w', '-\b', 'é\b', 'a*\b', 'a+\b', '(a)\b', '[a]\b', '\x61\b', '(?<=a)\b' ) as $pattern ) { + $this->assertStringContainsString( "(?(?<=$word)(?!$word)|(?=$word))", WP_ICU_Regex_Translator::translate( $pattern ), $pattern ); + } + + $this->assertSame( ' concat cat_ écat ', $this->replace_matches( WP_ICU_Regex_Translator::translate( '\bcat\b' ), 'cat concat cat_ écat cat' ) ); + $this->assertSame( 'cat con é', $this->replace_matches( WP_ICU_Regex_Translator::translate( '\Bcat' ), 'cat concat écat' ) ); + $this->assertSame( " <\u{212A}> ak", $this->replace_matches( WP_ICU_Regex_Translator::translate( '\bk\b', 'i' ), "k \u{212A} ak" ) ); + $this->assertSame( 'ab', $this->replace_matches( WP_ICU_Regex_Translator::translate( 'a\bb' ), 'ab' ) ); + } + public function test_unknown_flags_are_rejected(): void { $this->expectException( WP_ICU_Regex_Exception::class ); WP_ICU_Regex_Translator::translate( 'a', 'x' );