From 3162afca727e4db7a6f77ffab83c515ee21ec6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Thu, 12 Nov 2026 14:21:32 +0100 Subject: [PATCH 1/5] Read \K as a literal K, like ICU ICU reads "\K" as the letter "K", also in a set. PCRE reads it as a reset of the match start, so 'aKb' REGEXP 'a\\Kb' returned 0, where MySQL returns 1. The reset can also move the start of a match to before the place where the search started, like in "(?<=\Ka)". A loop that searches for one match after another would then find the same match forever. --- ...s-wp-sqlite-pdo-user-defined-functions.php | 12 ++++++++-- .../tests/WP_MySQL_On_SQLite_Tests.php | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php index 59ce53e1e..96b1658e5 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 @@ -1147,7 +1147,8 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false ) { } /** - * Escape pattern delimiters and NUL bytes that are not already escaped. + * Escape pattern delimiters and NUL bytes that are not already escaped, and + * read "\K" as "K". * * PHP before 8.2 rejects NUL bytes in patterns, so they become "\x00". * @@ -1160,6 +1161,13 @@ private function regexp_escape_pattern( $pattern ) { '/' => '\\/', "\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' ); + $escaped = ''; $quoted = false; $length = strlen( $pattern ); @@ -1179,7 +1187,7 @@ private function regexp_escape_pattern( $pattern ) { } if ( '\\' === $character && $i + 1 < $length ) { $next = $pattern[ $i + 1 ]; - $escaped .= isset( $special[ $next ] ) ? $special[ $next ] : $character . $next; + $escaped .= isset( $escapes[ $next ] ) ? $escapes[ $next ] : $character . $next; $quoted = 'Q' === $next; ++$i; } elseif ( isset( $special[ $character ] ) ) { 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 5b98e3408..f438c81ce 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 @@ -690,6 +690,30 @@ 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" + ); + $this->assertEquals( + array( + (object) array( + 'letter' => '1', + 'no_reset' => '0', + 'operator_result' => '1', + 'in_set' => '1', + 'quoted' => '1', + ), + ), + $this->last_result + ); + } + /** * @dataProvider regexpUnterminatedQuoteCases */ From 951a96a6f4215fc9703497c75d0fba5727089a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Thu, 12 Nov 2026 12:36:33 +0100 Subject: [PATCH 2/5] Add REGEXP_REPLACE() UDF Implement MySQL's REGEXP_REPLACE(expr, pattern, replacement [, pos [, occurrence [, match_type]]]). Positions count characters, not bytes. An occurrence of 0 replaces every match, and a negative one replaces the first. Like in MySQL, pos may be one past the end, and an empty subject is returned unchanged. The replacement follows MySQL's ICU syntax: "$N" and "${name}" insert capture groups, a backslash escapes the next character, and invalid references are errors. Matches are found one at a time with preg_match() offsets, so lookbehind sees the text before pos. After an empty match, the search continues one character later, like in ICU. Like REGEXP_LIKE(), the function matches data that is not valid UTF-8 byte by byte, and positions then count bytes, as MySQL does for binary strings. The subject, the pattern, and the replacement are passed as text, as PDO narrows integer arguments to 32 bits. --- .../src/sqlite/class-wp-mysql-on-sqlite.php | 6 +- ...s-wp-sqlite-pdo-user-defined-functions.php | 261 ++++- .../tests/WP_MySQL_On_SQLite_Tests.php | 364 +++++- ...P_MySQL_On_SQLite_Regexp_Replace_Tests.php | 1028 ++++++++++++++++- 4 files changed, 1617 insertions(+), 42 deletions(-) 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 2437890e1..a394c490f 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 @@ -5396,8 +5396,10 @@ private function translate_function_call( WP_Parser_Node $node ): string { case 'VERSION': return $this->quote_sqlite_value( $this->get_mysql_server_version_string() ); case 'REGEXP_LIKE': - // PDO narrows integer UDF arguments to 32 bits, so pass the subject and the pattern as text. - $text_args = min( count( $args ), 2 ); + case 'REGEXP_REPLACE': + // PDO narrows integer UDF arguments to 32 bits, so pass the subject, the + // pattern, and REGEXP_REPLACE's replacement as text. + $text_args = min( count( $args ), 'REGEXP_REPLACE' === $name ? 3 : 2 ); for ( $i = 0; $i < $text_args; $i++ ) { $args[ $i ] = sprintf( 'CAST(%s AS TEXT)', $args[ $i ] ); } 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 96b1658e5..2a7be6a72 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 @@ -65,6 +65,7 @@ public static function register_for( $pdo ): self { 'isnull' => 'isnull', 'regexp' => 'regexp', 'regexp_like' => 'regexp_like', + 'regexp_replace' => 'regexp_replace', 'field' => 'field', 'log' => 'log', 'least' => 'least', @@ -98,11 +99,12 @@ public static function register_for( $pdo ): self { * @var array */ private $function_arities = array( - 'regexp' => array( 2, 3 ), - 'regexp_like' => array( 2, 3 ), + 'regexp' => array( 2, 3 ), + 'regexp_like' => array( 2, 3 ), + 'regexp_replace' => array( 3, 4, 5, 6 ), ); - /** @var string[] Compiled PCRE patterns, keyed by byte mode, match type, and pattern. */ + /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ private $regexp_cache = array(); /** @@ -634,6 +636,88 @@ public function regexp_like( $expr, $pattern, $match_type = '' ) { return $this->regexp_match( $compiled, $pattern, $expr ); } + /** + * Method to emulate MySQL REGEXP_REPLACE() function. + * + * The replacement follows ICU: "$N" inserts a capture group ("$0" is the whole + * match), "${name}" a named group, and a backslash escapes the next character. + * + * @param string|null $expr The subject string. + * @param string|null $pattern The regex pattern. + * @param string|null $replacement The replacement template. + * @param int|float|string|null $pos Optional. The 1-based character position to start at. + * It may be one past the last character. + * @param int|float|string|null $occurrence Optional. Which match to replace, or 0 for all of + * them. A negative value replaces the first match. + * @param string|null $match_type Optional. Letters that change how the pattern matches. + * + * @throws Exception If the match type has an unknown letter, the pattern or the + * replacement is invalid, or pos is out of range. + * @return string|null The subject with the matches replaced, or NULL if any argument is NULL. + */ + public function regexp_replace( $expr, $pattern, $replacement, $pos = 1, $occurrence = 0, $match_type = '' ) { + // Like MySQL, check the arguments in this order, so that a NULL argument makes + // the result NULL only when the checks before it pass. + $this->regexp_check_match_type( 'regexp_replace', $match_type ); + if ( null === $match_type ) { + return null; + } + + // Like REGEXP_LIKE(), match data that is not valid UTF-8 byte by byte. + $byte_mode = ! $this->regexp_is_utf8( $pattern ) || ! $this->regexp_is_utf8( $expr ); + $match_type = $byte_mode ? 'c' . $match_type : $match_type; + if ( null !== $pattern ) { + $this->regexp_compile( $pattern, $match_type, $byte_mode ); + } + if ( null === $pos || null === $occurrence ) { + return null; + } + if ( (int) $pos < 1 ) { + throw new Exception( "Incorrect parameters in the call to native function 'regexp_replace'" ); + } + if ( null === $expr || null === $pattern || null === $replacement ) { + return null; + } + + $compiled = $this->regexp_compile( $pattern, $match_type, $byte_mode ); + $byte_start = $this->regexp_char_to_byte_offset( $expr, (int) $pos, true, $byte_mode ); + if ( '' === $expr ) { + return $expr; + } + + // An occurrence of 0 replaces every match, and a negative one the first match. + $occurrence = (int) $occurrence; + if ( $occurrence < 0 ) { + $occurrence = 1; + } + + /* + * List the capture group keys, by index and name. preg_match_all() + * reports every group even when nothing matches, while preg_match() + * omits trailing unmatched groups before PHP 7.4. + */ + preg_match_all( $compiled, '', $groups ); + $group_keys = array_flip( array_keys( $groups ) ); + + // Rebuild the subject while going through the matches. With a positive + // occurrence, replace only that match. + $result = substr( $expr, 0, $byte_start ); + $offset = $byte_start; + $index = 0; + foreach ( $this->regexp_matches( $pattern, $match_type, $byte_mode, $expr, $byte_start ) as $match ) { + if ( ++$index < $occurrence ) { + continue; + } + $result .= substr( $expr, $offset, $match[0][1] - $offset ); + $result .= $this->regexp_expand_replacement( $replacement, $match, $group_keys ); + $offset = $match[0][1] + strlen( $match[0][0] ); + if ( $occurrence > 0 ) { + break; + } + } + return $result . substr( $expr, $offset ); + } + /** * Method to emulate MySQL FIELD() function. * @@ -1048,28 +1132,36 @@ private function regexp_check_match_type( $function_name, $match_type ) { * collation isn't known here. * - PCRE doesn't match "ß" with "ss" when ignoring case, `$` also matches * between CR and LF, and `(?P...)` is valid. + * - `\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 can differ between rows. + * sensitivity, and whether positions count bytes, can differ between rows. * - SQLite converts numbers to text in its own format, so `20e0` reads "20.0" * (MySQL: "20"), and `0.000001` reads "1.0e-06". + * - `pos` and `occurrence` use PHP's integer conversion, so `2.6` means 2 + * (MySQL: 3), and `'2e1'` means 20 (MySQL: 2). * - A repeated group, like `(a|b)*`, can exceed PCRE's limits on a subject of * about 50,000 characters, or 2,000 on PHP 7.2. * * @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. * * @throws Exception If the pattern is empty or invalid. * @return string PCRE-ready pattern with delimiter and modifiers. */ - private function regexp_compile( $pattern, $match_type, $binary_mode = false ) { + 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.' ); } - $cache_key = ( $binary_mode ? 'bytes:' : 'text:' ) . $match_type . ':' . $pattern; + + // Without "\G" in the pattern, both versions are the same. + $without_g = $without_g && false !== strpos( $pattern, '\\G' ); + $cache_key = ( $binary_mode ? 'bytes:' : 'text:' ) . ( $without_g ? 'without-g:' : '' ) . $match_type . ':' . $pattern; if ( isset( $this->regexp_cache[ $cache_key ] ) ) { return $this->regexp_cache[ $cache_key ]; } @@ -1122,7 +1214,7 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false ) { } else { $newline = '(*ANY)'; } - $compiled = '/' . $newline . $this->regexp_escape_pattern( $pattern ) . '/' . $modifiers; + $compiled = '/' . $newline . $this->regexp_escape_pattern( $pattern, $without_g ) . '/' . $modifiers; /* * Compile the pattern by matching it against an empty string. Only a compile @@ -1147,16 +1239,17 @@ private function regexp_compile( $pattern, $match_type, $binary_mode = false ) { } /** - * Escape pattern delimiters and NUL bytes that are not already escaped, and - * read "\K" as "K". + * 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 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 ) { + private function regexp_escape_pattern( $pattern, $without_g = false ) { $special = array( '/' => '\\/', "\0" => '\\x00', @@ -1167,6 +1260,11 @@ private function regexp_escape_pattern( $pattern ) { * 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; @@ -1208,12 +1306,140 @@ private function regexp_escape_pattern( $pattern ) { /** * Check whether a string is valid UTF-8. * - * @param string $value The string. + * @param string|null $value The string. NULL counts as valid. * * @return bool Whether the string is valid UTF-8. */ private function regexp_is_utf8( $value ) { - return 1 === preg_match( '//u', $value ); + return null === $value || 1 === preg_match( '//u', $value ); + } + + /** + * Convert a 1-based character position to a byte offset. + * + * @param string $subject The subject string. + * @param int $position The 1-based character position. + * @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. + * @return int The byte offset. + */ + private function regexp_char_to_byte_offset( $subject, $position, $allow_past_end, $byte_mode ) { + $length = strlen( $subject ); + $chars = 0; + for ( $offset = 0; $offset < $length; $offset++ ) { + // Every byte except a UTF-8 continuation byte starts a character. + if ( $byte_mode || 0x80 !== ( ord( $subject[ $offset ] ) & 0xC0 ) ) { + if ( ++$chars === $position ) { + return $offset; + } + } + } + if ( $allow_past_end && $chars + 1 === $position ) { + return $length; + } + throw new Exception( 'Index out of bounds in regular expression search.' ); + } + + /** + * Expand an ICU replacement template for one match. + * + * - A backslash escapes the next character, and a trailing one is dropped. + * Unlike ICU, "\uXXXX" and "\UXXXXXXXX" are not expanded. + * - "$N" inserts group N. It takes the longest run of digits that is a group + * number, and the other digits stay literal. A larger number is an error. + * Unlike ICU, only the ASCII digits 0-9 are read as digits. + * - "${name}" inserts a named group. An unknown name is an error, and so are + * "${N}" and a "$" before anything else. + * - A group that didn't match inserts an empty string. + * + * @param string $replacement The replacement template. + * @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. + * @return string The expanded replacement. + */ + private function regexp_expand_replacement( $replacement, $match_data, $group_keys ) { + /* + * Like ICU, accept only letters and the digits 1-9 in a group name. A name + * must start with a letter, or "${1}" would match group 1's numeric key. + */ + return preg_replace_callback( + '/\\\\(.?)|\$(?:\{([A-Za-z][A-Za-z1-9]*)\}|(\d+))?/s', + static function ( $parts ) use ( $match_data, $group_keys ) { + if ( '\\' === $parts[0][0] ) { + return $parts[1]; + } + $name = $parts[2] ?? ''; + $digits = $parts[3] ?? ''; + if ( '' !== $name && isset( $group_keys[ $name ] ) ) { + return $match_data[ $name ][0] ?? ''; + } + if ( '' === $digits ) { + throw new Exception( 'A capture group has an invalid name.' ); + } + for ( $length = strlen( $digits ); $length > 0; --$length ) { + $group = (int) substr( $digits, 0, $length ); + if ( isset( $group_keys[ $group ] ) ) { + return ( $match_data[ $group ][0] ?? '' ) . substr( $digits, $length ); + } + } + throw new Exception( 'Index out of bounds in regular expression search.' ); + }, + $replacement + ); + } + + /** + * Find the matches from an offset, one at a time. + * + * The search starts at the offset of the whole subject, so that lookbehinds + * see the text before it. Like in ICU, "\G" matches only at the start of the + * subject and where the previous match ended. + * + * @param string $pattern The MySQL regex pattern. + * @param string $match_type MySQL match_type flag string. + * @param bool $byte_mode Whether every byte is a character. + * @param string $subject The subject string. + * @param int $offset The byte offset to start at. + * + * @throws Exception On a preg failure. + * @return Generator The matches, with offsets. + */ + private function regexp_matches( $pattern, $match_type, $byte_mode, $subject, $offset ) { + $compiled = $this->regexp_compile( $pattern, $match_type, $byte_mode ); + $without_g = $this->regexp_compile( $pattern, $match_type, $byte_mode, true ); + $length = strlen( $subject ); + $previous_end = 0; + while ( $offset <= $length ) { + $search = $offset === $previous_end ? $compiled : $without_g; + 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] ); + $previous_end = $offset; + if ( '' === $match[0][0] ) { + // Like ICU, continue one character after an empty match, even when the + // pattern could match a non-empty string at the same position. + ++$offset; + while ( ! $byte_mode && $offset < $length && 0x80 === ( ord( $subject[ $offset ] ) & 0xC0 ) ) { + ++$offset; + } + } + } } /** @@ -1222,12 +1448,15 @@ private function regexp_is_utf8( $value ) { * @param string $compiled PCRE-wrapped pattern. * @param string $pattern The original MySQL regex pattern, for error messages. * @param string $subject The subject string. + * @param array $matches Optional. Receives the match, like in preg_match(). + * @param int $flags Optional. The preg_match() flags. + * @param int $offset Optional. The byte offset to start at. * * @throws Exception On a preg failure. * @return int 1 on match, 0 on no match. */ - private function regexp_match( $compiled, $pattern, $subject ) { - $result = preg_match( $compiled, $subject ); + private function regexp_match( $compiled, $pattern, $subject, &$matches = null, $flags = 0, $offset = 0 ) { + $result = preg_match( $compiled, $subject, $matches, $flags, $offset ); /* * PHP's JIT stack is small, so a repeated group, such as "(a|b)*", can fail on @@ -1235,7 +1464,7 @@ private function regexp_match( $compiled, $pattern, $subject ) { * PHP 7.2 has no "(*NO_JIT)", and matching without JIT can crash it. */ if ( false === $result && PREG_JIT_STACKLIMIT_ERROR === preg_last_error() && PHP_VERSION_ID >= 70300 ) { - $result = preg_match( $compiled[0] . '(*NO_JIT)' . substr( $compiled, 1 ), $subject ); + $result = preg_match( $compiled[0] . '(*NO_JIT)' . substr( $compiled, 1 ), $subject, $matches, $flags, $offset ); } if ( false === $result ) { $this->regexp_fail( $pattern ); diff --git a/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php b/packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php index f438c81ce..47899fc35 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 @@ -356,26 +356,35 @@ public static function regexpMatchTypeFlagCases() { } /** - * @dataProvider regexpLikeBinaryDataCases + * @dataProvider regexpBinaryDataCases */ - public function testRegexpLikeMatchesBinaryDataByBytes( $value, $sql, $expected ) { - // Like the REGEXP operator, REGEXP_LIKE() matches data that is not valid UTF-8 - // byte by byte, and case-sensitively, unless the match type says otherwise. + public function testRegexpFunctionsMatchBinaryDataByBytes( $value, $sql, $expected ) { + // Like the REGEXP operator, the functions match data that is not valid UTF-8 byte + // by byte, and case-sensitively, unless the match type says otherwise. Positions + // count bytes then, like in MySQL binary strings. $this->assertQuery( 'CREATE TABLE blobs (b BLOB)' ); $this->assertQuery( "INSERT INTO blobs VALUES ($value)" ); $this->assertQuery( "SELECT $sql AS r FROM blobs" ); $this->assertSame( $expected, $this->last_result[0]->r ); } - public static function regexpLikeBinaryDataCases() { + public static function regexpBinaryDataCases() { return array( - 'any byte' => array( "X'61FF62'", "REGEXP_LIKE(b, 'a.b')", '1' ), - 'other case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'A.B')", '0' ), - 'ignore case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'A.B', 'i')", '1' ), - 'match case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'a.b', 'c')", '1' ), - '0x85 in a character' => array( "X'78C485FF79'", "REGEXP_LIKE(b, 'x.*y')", '1' ), - 'CR' => array( "X'610D62FF'", "REGEXP_LIKE(b, 'a.b')", '0' ), - 'CR, Unix line break' => array( "X'610D62FF'", "REGEXP_LIKE(b, 'a.b', 'u')", '1' ), + 'any byte' => array( "X'61FF62'", "REGEXP_LIKE(b, 'a.b')", '1' ), + 'other case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'A.B')", '0' ), + 'ignore case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'A.B', 'i')", '1' ), + 'match case' => array( "X'61FF62'", "REGEXP_LIKE(b, 'a.b', 'c')", '1' ), + '0x85 in a character' => array( "X'78C485FF79'", "REGEXP_LIKE(b, 'x.*y')", '1' ), + 'CR' => array( "X'610D62FF'", "REGEXP_LIKE(b, 'a.b')", '0' ), + 'CR, Unix line break' => array( "X'610D62FF'", "REGEXP_LIKE(b, 'a.b', 'u')", '1' ), + + 'REGEXP_REPLACE, any byte' => array( "X'61FF62'", "REGEXP_REPLACE(b, 'a.b', 'x')", 'x' ), + 'REGEXP_REPLACE, other case' => array( "X'61FF41'", "REGEXP_REPLACE(b, 'a', 'x')", "x\xFFA" ), + 'REGEXP_REPLACE, ignore case' => array( "X'61FF41'", "REGEXP_REPLACE(b, 'a', 'x', 1, 0, 'i')", "x\xFFx" ), + 'REGEXP_REPLACE, pos' => array( "X'C485FF61'", "REGEXP_REPLACE(b, '.', 'x', 3)", "\xC4\x85xx" ), + 'REGEXP_REPLACE, pos one past end' => array( "X'C485FF'", "REGEXP_REPLACE(b, '\$', 'x', 4)", "\xC4\x85\xFFx" ), + 'REGEXP_REPLACE, occurrence' => array( "X'C485FF'", "REGEXP_REPLACE(b, '(.)', '[\$1]', 2, 1)", "\xC4[\x85]\xFF" ), + 'REGEXP_REPLACE, empty matches' => array( "X'C485FF'", "REGEXP_REPLACE(b, 'x*', '-')", "-\xC4-\x85-\xFF-" ), ); } @@ -751,6 +760,310 @@ public function testRegexpUnicodeNewlineHandling() { $this->assertSame( '1', $this->last_result[0]->r ); } + /** + * @dataProvider regexpReplaceBasicCases + */ + public function testRegexpReplaceBasic( $expr, $pattern, $replacement, $expected ) { + $this->assertQuery( + sprintf( + "SELECT REGEXP_REPLACE('%s', '%s', '%s') AS r", + addslashes( $expr ), + addslashes( $pattern ), + addslashes( $replacement ) + ) + ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpReplaceBasicCases() { + return array( + 'simple' => array( 'abcabc', 'b', 'X', 'aXcaXc' ), + 'no match' => array( 'abc', 'z', 'X', 'abc' ), + 'quantifier' => array( 'aabbcc', 'b+', 'B', 'aaBcc' ), + 'groups' => array( 'John Doe', '(\\w+) (\\w+)', '$2 $1', 'Doe John' ), + 'case-insensitive' => array( 'ABC', 'abc', 'x', 'x' ), + ); + } + + /** + * @dataProvider regexpReplaceErrors + */ + public function testRegexpReplaceErrors( $sql, $message ) { + $this->assertQueryError( "SELECT $sql", $message ); + } + + public static function regexpReplaceErrors() { + // 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_replace'"; + return array( + 'pos zero' => array( "REGEXP_REPLACE('abc', 'a', 'X', 0)", $pos_error ), + 'pos negative' => array( "REGEXP_REPLACE('abc', 'a', 'X', -1)", $pos_error ), + 'pos zero, empty subject' => array( "REGEXP_REPLACE('', 'a', 'X', 0)", $pos_error ), + '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 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' ), + 'extra argument' => array( + "REGEXP_REPLACE('abc', 'a', 'x', 1, 0, 'c', 'extra')", + 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_REPLACE()', + ), + ); + } + + /** + * @dataProvider regexpReplaceFullCases + */ + public function testRegexpReplaceFull( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpReplaceFullCases() { + return array( + // pos: only replace from position 3 onward (1-based, character). + 'pos=3' => array( "REGEXP_REPLACE('abcabc', 'b', 'X', 3)", 'abcaXc' ), + // occurrence=1: replace only the first match after pos. + 'occurrence=1 from start' => array( "REGEXP_REPLACE('abcabc', 'b', 'X', 1, 1)", 'aXcabc' ), + // occurrence=2 from start. + 'occurrence=2 from start' => array( "REGEXP_REPLACE('abcabc', 'b', 'X', 1, 2)", 'abcaXc' ), + // occurrence=0 means all matches from pos. + 'occurrence=0 from pos 3' => array( "REGEXP_REPLACE('abcabc', 'b', 'X', 3, 0)", 'abcaXc' ), + // match_type c with default pos/occurrence. + 'match_type c' => array( "REGEXP_REPLACE('ABC', 'abc', 'x', 1, 0, 'c')", 'ABC' ), + // match_type i. + 'match_type i' => array( "REGEXP_REPLACE('ABC', 'abc', 'x', 1, 0, 'i')", 'x' ), + // Multi-byte pos: skip the first character, replace only in the rest. + 'multibyte pos' => array( "REGEXP_REPLACE('éabc', 'a', 'X', 2)", 'éXbc' ), + // MySQL allows pos = char_count + 1. + 'pos one past end' => array( "REGEXP_REPLACE('abc', 'a', 'X', 4)", 'abc' ), + 'zero-width at end' => array( "REGEXP_REPLACE('abc', '\$', 'X', 4)", 'abcX' ), + 'null expr' => array( "REGEXP_REPLACE(NULL, 'a', 'b')", null ), + 'null pattern' => array( "REGEXP_REPLACE('abc', NULL, 'b')", null ), + 'null replacement' => array( "REGEXP_REPLACE('abc', 'a', NULL)", null ), + // A NULL match_type returns NULL before the pattern and pos are checked. + 'null match_type first' => array( "REGEXP_REPLACE('abc', '(abc', 'x', 0, 0, NULL)", null ), + // A NULL occurrence returns NULL before pos is checked. + 'null occurrence, pos 0' => array( "REGEXP_REPLACE('abc', 'a', 'x', 0, NULL)", null ), + ); + } + + public function testRegexpReplaceNumericOperands() { + $this->assertQuery( "SELECT REGEXP_REPLACE(123, '2', 9) AS r" ); + $this->assertSame( '193', $this->last_result[0]->r ); + } + + public function testRegexpReplaceOccurrenceBeyondMatches() { + // MySQL: if occurrence exceeds the number of matches, return subject unchanged. + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', 'a', 'X', 1, 5) AS r" ); + $this->assertSame( 'abc', $this->last_result[0]->r ); + } + + public function testRegexpReplaceNegativeOccurrenceClamped() { + // MySQL clamps negative occurrence to 1; 0 still means "replace all". + $this->assertQuery( "SELECT REGEXP_REPLACE('abcabc', 'b', 'X', 1, -100) AS r" ); + $this->assertSame( 'aXcabc', $this->last_result[0]->r ); + } + + public function testRegexpReplaceOccurrenceBackreferenceForms() { + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(a)(b)(c)', '\$2\$1', 1, 1) AS r" ); + $this->assertSame( 'ba', $this->last_result[0]->r ); + } + + 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.' + ); + } + + public function testRegexpReplaceNamedGroupReference() { + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)', '[\${x}]') AS r" ); + $this->assertSame( 'a[b]c', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)(?c)', '[\${y}\${x}\$1]') AS r" ); + $this->assertSame( 'a[cbb]', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)', '[\${x1}]') AS r" ); + $this->assertSame( 'a[b]c', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)', '[\${B}]') AS r" ); + $this->assertSame( 'a[b]c', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)', '[\${x}1]') AS r" ); + $this->assertSame( 'a[b1]c', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(?b)', '\\\\\${x}') AS r" ); + $this->assertSame( 'a${x}c', $this->last_result[0]->r ); + + // Unmatched named groups expand to an empty string. + $this->assertQuery( "SELECT REGEXP_REPLACE('ac', '(?b)?c', '[\${x}]') AS r" ); + $this->assertSame( 'a[]', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('a', 'a(?b)?', '[\${x}]') AS r" ); + $this->assertSame( '[]', $this->last_result[0]->r ); + } + + public function testRegexpReplaceInvalidNamedGroupReference() { + $cases = array( + array( '(?b)', '[${x]' ), + array( '(?b)', '[${}]' ), + array( '(?b)', '[${y}]' ), + array( '(?b)', '[${ x}]' ), + array( '(?b)', '[$x]' ), + array( '(?b)', '[${a}]' ), + array( '(?b)', '[${b}]' ), + // ICU names in "${name}" exclude the digit 0. + array( '(?b)', '[${x0}]' ), + ); + foreach ( $cases as $case ) { + list( $pattern, $replacement ) = $case; + $this->assertQueryError( + "SELECT REGEXP_REPLACE('abc', '$pattern', '$replacement')", + 'A capture group has an invalid name.' + ); + } + } + + public function testRegexpReplaceBackslashDigitIsLiteral() { + // MySQL strips backslash before any character; "\2\1" becomes "21". + $this->assertQuery( "SELECT REGEXP_REPLACE('xyzabc', '(a)(b)(c)', '\\\\2\\\\1', 1, 1) AS r" ); + $this->assertSame( 'xyz21', $this->last_result[0]->r ); + } + + public function testRegexpReplaceFullMatchBackref() { + // "$0" is the whole match. + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', 'b', '[\$0]') AS r" ); + $this->assertSame( 'a[b]c', $this->last_result[0]->r ); + } + + public function testRegexpReplaceBackslashZeroIsLiteral() { + // "\0" is literal "0", not the full match. + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', 'b', '[\\\\0]') AS r" ); + $this->assertSame( 'a[0]c', $this->last_result[0]->r ); + } + + public function testRegexpReplaceDollarDigitGreedyFallback() { + // "$10" with a single capture group is "$1" followed by literal "0". + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', '(b)', '[\$10]') AS r" ); + $this->assertSame( 'a[b0]c', $this->last_result[0]->r ); + } + + public function testRegexpReplaceDollarWithoutDigitErrors() { + $this->assertQueryError( + "SELECT REGEXP_REPLACE('abc', 'b', 'x\$y')", + '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.' + ); + } + + public function testRegexpReplacePreservesNumericCaptureIndexes() { + $this->assertQuery( "SELECT REGEXP_REPLACE('a', '(?a)(?b)?', '[\$2]') AS r" ); + $this->assertSame( '[]', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('a', '(a)|(b)', '[\$2]') AS r" ); + $this->assertSame( '[]', $this->last_result[0]->r ); + } + + public function testRegexpReplaceTrailingUnmatchedGroups() { + // Unmatched groups at the end of the pattern still count as groups. + $this->assertQuery( "SELECT REGEXP_REPLACE('a', 'a(b)?', '[\$1]') AS r" ); + $this->assertSame( '[]', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('aa', 'a(b)?', '[\$1]') AS r" ); + $this->assertSame( '[][]', $this->last_result[0]->r ); + + // "$10" refers to the tenth group even when groups 2-10 did not match. + $pattern = '(a)(b)?(c)?(d)?(e)?(f)?(g)?(h)?(i)?(j)?'; + $this->assertQuery( "SELECT REGEXP_REPLACE('ab', '$pattern', '[\$10]') AS r" ); + $this->assertSame( '[]', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('ab', '$pattern', '[\$11]') AS r" ); + $this->assertSame( '[a1]', $this->last_result[0]->r ); + } + + public function testRegexpReplaceTrailingBackslashDropped() { + // Trailing lone backslash is dropped (matches MySQL). + $this->assertQuery( "SELECT REGEXP_REPLACE('a', 'a', 'x\\\\') AS r" ); + $this->assertSame( 'x', $this->last_result[0]->r ); + } + + public function testRegexpReplaceBackslashLetterIsLiteral() { + // "\q" -> "q" (backslash stripped before any char, including letters). + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', 'b', '[\\\\q]') AS r" ); + $this->assertSame( 'a[q]c', $this->last_result[0]->r ); + } + + public function testRegexpReplaceOccurrenceLookbehind() { + // A lookbehind sees the text before the match, also when only one match is replaced. + $this->assertQuery( "SELECT REGEXP_REPLACE('abcabc', '(?<=a)b', 'X', 1, 1) AS r" ); + $this->assertSame( 'aXcabc', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abcabc', '(?<=a)b', 'X', 1, 2) AS r" ); + $this->assertSame( 'abcaXc', $this->last_result[0]->r ); + } + + public function testRegexpReplaceLookbehindAcrossPos() { + // The lookbehind sees bytes before pos because the full subject is kept. + $this->assertQuery( "SELECT REGEXP_REPLACE('ab', '(?<=a)b', 'X', 2) AS r" ); + $this->assertSame( 'aX', $this->last_result[0]->r ); + } + + public function testRegexpReplaceOccurrenceZeroWidth() { + // Zero-width match at a word boundary. + $this->assertQuery( "SELECT REGEXP_REPLACE('abc def', '\\\\b', '|', 1, 1) AS r" ); + $this->assertSame( '|abc def', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('abc def', '\\\\b', '|', 1, 2) AS r" ); + $this->assertSame( 'abc| def', $this->last_result[0]->r ); + } + + public function testRegexpReplaceOccurrenceLiteralEscapes() { + // \\ -> literal backslash in the replacement. SQL string literal tricks: + // PHP source "\\\\\\\\" is 4 backslashes, which SQL parses as 2 backslashes + // received by the function; the replacement grammar expander folds those + // to a single literal backslash. + $this->assertQuery( "SELECT REGEXP_REPLACE('a', 'a', '\\\\\\\\', 1, 1) AS r" ); + $this->assertSame( '\\', $this->last_result[0]->r ); + } + + public function testRegexpReplaceEmptyReplacement() { + $this->assertQuery( "SELECT REGEXP_REPLACE('abc', 'b', '') AS r" ); + $this->assertSame( 'ac', $this->last_result[0]->r ); + } + + public function testRegexpReplaceLeavesEmptySubjectUnchanged() { + $this->assertQuery( "SELECT REGEXP_REPLACE('', '\$', 'X') AS r" ); + $this->assertSame( '', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_REPLACE('', '\$', '\$x') AS r" ); + $this->assertSame( '', $this->last_result[0]->r ); + } + + /** + * @dataProvider regexpMatchEndAnchorCases + */ + public function testRegexpMatchEndAnchor( $sql, $expected ) { + // Like in ICU, "\G" matches only at the start of the subject and where the + // previous match ended. So it doesn't match at pos, or after an empty match. + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpMatchEndAnchorCases() { + return array( + 'REGEXP_REPLACE, empty matches' => array( "REGEXP_REPLACE('abc', '\\\\G', '-')", '-abc' ), + 'REGEXP_REPLACE, after a match' => array( "REGEXP_REPLACE('aab', '\\\\Ga', '-')", '--b' ), + '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' ), + ); + } + /** * @dataProvider regexpBigIntegerCases */ @@ -762,16 +1075,19 @@ public function testRegexpBigIntegerOperands( $sql, $expected ) { public static function regexpBigIntegerCases() { return array( // The smallest values that don't fit in 32 bits. - '2^31, subject' => array( "REGEXP_LIKE(2147483648, '^2147483648\$')", '1' ), - '-2^31 - 1, subject' => array( "REGEXP_LIKE(-2147483649, '^-2147483649\$')", '1' ), - 'largest BIGINT' => array( "REGEXP_LIKE(9223372036854775807, '^9223372036854775807\$')", '1' ), + '2^31, subject' => array( "REGEXP_LIKE(2147483648, '^2147483648\$')", '1' ), + '-2^31 - 1, subject' => array( "REGEXP_LIKE(-2147483649, '^-2147483649\$')", '1' ), + 'largest BIGINT' => array( "REGEXP_LIKE(9223372036854775807, '^9223372036854775807\$')", '1' ), - 'REGEXP_LIKE subject' => array( "REGEXP_LIKE(9999999999, '^9')", '1' ), - 'REGEXP_LIKE pattern' => array( "REGEXP_LIKE('9999999999', 9999999999)", '1' ), - 'operator subject' => array( "9999999999 REGEXP '^9'", '1' ), - 'operator pattern' => array( "'9999999999' REGEXP 9999999999", '1' ), - 'negated operator' => array( "9999999999 NOT REGEXP '^9'", '0' ), - 'REGEXP BINARY' => array( "9999999999 REGEXP BINARY '^9'", '1' ), + 'REGEXP_LIKE subject' => array( "REGEXP_LIKE(9999999999, '^9')", '1' ), + 'REGEXP_LIKE pattern' => array( "REGEXP_LIKE('9999999999', 9999999999)", '1' ), + 'REGEXP_REPLACE' => array( "REGEXP_REPLACE(9999999999, '9', '1')", '1111111111' ), + 'REGEXP_REPLACE regex' => array( "REGEXP_REPLACE('9999999999', 9999999999, 'x')", 'x' ), + 'replacement' => array( "REGEXP_REPLACE('a', 'a', 9999999999)", '9999999999' ), + 'operator subject' => array( "9999999999 REGEXP '^9'", '1' ), + 'operator pattern' => array( "'9999999999' REGEXP 9999999999", '1' ), + 'negated operator' => array( "9999999999 NOT REGEXP '^9'", '0' ), + 'REGEXP BINARY' => array( "9999999999 REGEXP BINARY '^9'", '1' ), ); } @@ -781,7 +1097,8 @@ public function testRegexpBigIntegerColumn() { $this->assertQuery( "SELECT phone REGEXP '^1' AS operator_result, - REGEXP_LIKE(phone, '^1') AS like_result + REGEXP_LIKE(phone, '^1') AS like_result, + REGEXP_REPLACE(phone, '^1', '') AS replace_result FROM phones ORDER BY id" ); $this->assertEquals( @@ -789,14 +1106,17 @@ public function testRegexpBigIntegerColumn() { (object) array( 'operator_result' => '1', 'like_result' => '1', + 'replace_result' => '5551234567', ), (object) array( 'operator_result' => '0', 'like_result' => '0', + 'replace_result' => '42', ), (object) array( 'operator_result' => null, 'like_result' => null, + 'replace_result' => null, ), ), $this->last_result 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 588237d7f..4eae03f59 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 @@ -8,7 +8,1031 @@ class WP_MySQL_On_SQLite_Regexp_Replace_Tests extends WP_MySQL_On_SQLite_Regexp_Test_Case { const CHECKS = array( 'regexp_replace' ); - protected function setUp(): void { - $this->markTestSkipped( 'REGEXP_REPLACE() is not supported yet.' ); + 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: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', + '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-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', + 'icu-regextst:524', + 'icu-regextst:525', + 'icu-regextst:538', + 'icu-regextst:539', + 'icu-regextst:540', + 'icu-regextst:541', + 'icu-regextst:542', + 'icu-regextst:543', + 'icu-regextst:544', + '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', + 'icu-regextst:1226', + 'icu-regextst:1227', + 'icu-regextst:1228', + 'icu-regextst:1231', + 'icu-regextst:1232', + 'icu-regextst:1239', + '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', + 'icu-regextst:1252', + 'icu-regextst:1253', + 'icu-regextst:1254', + 'icu-regextst:1255', + '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', + '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', + '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:1872', + 'icu-regextst:1873', + 'icu-regextst:2768', + 'icu-regextst:2769', + 'icu-regextst:2770', + 'icu-regextst:2771', + 'icu-regextst:2772', + 'icu-regextst:2773', + 'icu-regextst:2774', + 'icu-regextst:2775', + 'icu-regextst:2776', + 'icu-regextst:2777', + 'icu-regextst:2778', + 'icu-regextst:2779', + 'icu-regextst:3338', + 'icu-regextst:3339', + 'icu-regextst:3340', + 'icu-regextst:3341', + 'icu-regextst:3342', + 'icu-regextst:3343', + 'icu-regextst:3344', + 'icu-regextst:3345', + 'icu-regextst:3396', + 'icu-regextst:3397', + 'icu-regextst:3398', + 'icu-regextst:3399', + 'icu-regextst:3400', + 'icu-regextst:3401', + 'icu-regextst:3402', + 'icu-regextst:3403', + 'icu-regextst:3508', + 'icu-regextst:3509', + 'icu-regextst:3518', + 'icu-regextst:3519', + 'icu-regextst:3520', + 'icu-regextst:3521', + 'icu-regextst:3522', + 'icu-regextst:3523', + 'icu-regextst:3524', + 'icu-regextst:3525', + 'icu-regextst:3538', + 'icu-regextst:3539', + 'icu-regextst:3540', + 'icu-regextst:3541', + 'icu-regextst:3542', + 'icu-regextst:3543', + 'icu-regextst:3544', + 'icu-regextst:3545', + 'icu-regextst:3606', + 'icu-regextst:3607', + 'icu-regextst:3608', + 'icu-regextst:3609', + 'icu-regextst:3610', + 'icu-regextst:3611', + 'icu-regextst:3836', + 'icu-regextst:3837', + 'icu-regextst:3838', + 'icu-regextst:3839', + ); + + // 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( + $failures, + 'mysql-server-suite:12583', + 'mysql-server-suite:12584', + 'icu-regextst:265', + 'icu-regextst:266', + 'icu-regextst:267', + 'icu-regextst:268' + ); + } + + // 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( + $failures, + 'mysql-server-suite:6471', + 'mysql-server-suite:6472' + ); + } + + // 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: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' + ); + } + + return $failures; } } From 8c9d9c448a9ca5e3c93d2e14515ed8aeed069fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Thu, 12 Nov 2026 12:39:28 +0100 Subject: [PATCH 3/5] Add REGEXP_SUBSTR() UDF Implement MySQL's REGEXP_SUBSTR(expr, pattern [, pos [, occurrence [, match_type]]]). It returns the matching substring, or NULL when there is no such match. Like in MySQL, an occurrence below 1 returns the first match, and pos may be one past the end, where an empty match can still be found. Matches are found like in REGEXP_REPLACE(), so lookbehind sees the text before pos, and the search continues one character after an empty match. Data that is not valid UTF-8 is matched byte by byte. --- .../src/sqlite/class-wp-mysql-on-sqlite.php | 1 + ...s-wp-sqlite-pdo-user-defined-functions.php | 69 ++ .../tests/WP_MySQL_On_SQLite_Tests.php | 110 +- ...WP_MySQL_On_SQLite_Regexp_Substr_Tests.php | 995 +++++++++++++++++- 4 files changed, 1171 insertions(+), 4 deletions(-) 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 a394c490f..d142e3d50 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 @@ -5396,6 +5396,7 @@ private function translate_function_call( WP_Parser_Node $node ): string { case 'VERSION': return $this->quote_sqlite_value( $this->get_mysql_server_version_string() ); case 'REGEXP_LIKE': + case 'REGEXP_SUBSTR': case 'REGEXP_REPLACE': // PDO narrows integer UDF arguments to 32 bits, so pass the subject, the // pattern, and REGEXP_REPLACE's replacement as text. 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 2a7be6a72..cad531a60 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 @@ -66,6 +66,7 @@ public static function register_for( $pdo ): self { 'regexp' => 'regexp', 'regexp_like' => 'regexp_like', 'regexp_replace' => 'regexp_replace', + 'regexp_substr' => 'regexp_substr', 'field' => 'field', 'log' => 'log', 'least' => 'least', @@ -102,6 +103,7 @@ public static function register_for( $pdo ): self { 'regexp' => array( 2, 3 ), 'regexp_like' => array( 2, 3 ), 'regexp_replace' => array( 3, 4, 5, 6 ), + 'regexp_substr' => array( 2, 3, 4, 5 ), ); /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ @@ -718,6 +720,50 @@ public function regexp_replace( $expr, $pattern, $replacement, $pos = 1, $occurr return $result . substr( $expr, $offset ); } + /** + * Method to emulate MySQL REGEXP_SUBSTR() function. + * + * @param string|null $expr The subject string. + * @param string|null $pattern The regex pattern. + * @param int|float|string|null $pos Optional. The 1-based character position to start at. + * It may be one past the last character. + * @param int|float|string|null $occurrence Optional. Which match to return. A value below 1 + * returns the first match. + * @param string|null $match_type Optional. Letters that change how the pattern matches. + * + * @throws Exception If the match type has an unknown letter, the pattern is invalid, + * or pos is out of range. + * @return string|null The match, or NULL if there is no match or any argument is NULL. + */ + public function regexp_substr( $expr, $pattern, $pos = 1, $occurrence = 1, $match_type = '' ) { + // Like MySQL, check the arguments in this order, so that a NULL argument makes + // the result NULL only when the checks before it pass. + $this->regexp_check_match_type( 'regexp_substr', $match_type ); + if ( null === $match_type ) { + return null; + } + + // Like REGEXP_LIKE(), match data that is not valid UTF-8 byte by byte. + $byte_mode = ! $this->regexp_is_utf8( $pattern ) || ! $this->regexp_is_utf8( $expr ); + $match_type = $byte_mode ? 'c' . $match_type : $match_type; + if ( null !== $pattern ) { + $this->regexp_compile( $pattern, $match_type, $byte_mode ); + } + if ( null === $pos || null === $occurrence ) { + return null; + } + if ( (int) $pos < 1 ) { + throw new Exception( "Incorrect parameters in the call to native function 'regexp_substr'" ); + } + if ( null === $expr || null === $pattern ) { + return null; + } + + $byte_start = $this->regexp_char_to_byte_offset( $expr, (int) $pos, true, $byte_mode ); + $match = $this->regexp_find_match( $pattern, $match_type, $byte_mode, $expr, $byte_start, (int) $occurrence ); + return null === $match ? null : $match[0][0]; + } + /** * Method to emulate MySQL FIELD() function. * @@ -1392,6 +1438,29 @@ static function ( $parts ) use ( $match_data, $group_keys ) { ); } + /** + * Find one match from an offset. + * + * @param string $pattern The MySQL regex pattern. + * @param string $match_type MySQL match_type flag string. + * @param bool $byte_mode Whether every byte is a character. + * @param string $subject The subject string. + * @param int $offset The byte offset to start at. + * @param int $occurrence Which match to find. A value below 1 finds the first match. + * + * @throws Exception On a preg failure. + * @return array|null The match, with offsets, or NULL if there is none. + */ + private function regexp_find_match( $pattern, $match_type, $byte_mode, $subject, $offset, $occurrence ) { + $index = 0; + foreach ( $this->regexp_matches( $pattern, $match_type, $byte_mode, $subject, $offset ) as $match ) { + if ( ++$index >= $occurrence ) { + return $match; + } + } + return null; + } + /** * Find the matches from an offset, one at a time. * 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 47899fc35..f128469ef 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 @@ -385,6 +385,14 @@ public static function regexpBinaryDataCases() { 'REGEXP_REPLACE, pos one past end' => array( "X'C485FF'", "REGEXP_REPLACE(b, '\$', 'x', 4)", "\xC4\x85\xFFx" ), 'REGEXP_REPLACE, occurrence' => array( "X'C485FF'", "REGEXP_REPLACE(b, '(.)', '[\$1]', 2, 1)", "\xC4[\x85]\xFF" ), 'REGEXP_REPLACE, empty matches' => array( "X'C485FF'", "REGEXP_REPLACE(b, 'x*', '-')", "-\xC4-\x85-\xFF-" ), + + 'REGEXP_SUBSTR, any byte' => array( "X'61FF62'", "REGEXP_SUBSTR(b, 'a.b')", "a\xFFb" ), + 'REGEXP_SUBSTR, other case' => array( "X'61FF41'", "REGEXP_SUBSTR(b, 'a.a')", null ), + 'REGEXP_SUBSTR, ignore case' => array( "X'61FF41'", "REGEXP_SUBSTR(b, 'a.a', 1, 1, 'i')", "a\xFFA" ), + 'REGEXP_SUBSTR, pos' => array( "X'C485FF61'", "REGEXP_SUBSTR(b, '.', 2)", "\x85" ), + 'REGEXP_SUBSTR, pos one past end' => array( "X'C485FF'", "REGEXP_SUBSTR(b, 'x*', 4)", '' ), + 'REGEXP_SUBSTR, occurrence' => array( "X'C485FF'", "REGEXP_SUBSTR(b, '.', 1, 3)", "\xFF" ), + 'REGEXP_SUBSTR, empty matches' => array( "X'C485FF'", "REGEXP_SUBSTR(b, 'x*', 1, 4)", '' ), ); } @@ -436,13 +444,15 @@ public function testRegexpJitStackLimit() { $this->assertQuery( "SELECT '$subject' REGEXP '^(a|b)*\$' AS operator_result, - REGEXP_LIKE('$subject', '^(a|b)*\$') AS like_result" + REGEXP_LIKE('$subject', '^(a|b)*\$') AS like_result, + LENGTH(REGEXP_SUBSTR('$subject', '(a|b)+')) AS substr_length" ); $this->assertEquals( array( (object) array( 'operator_result' => '1', 'like_result' => '1', + 'substr_length' => '20000', ), ), $this->last_result @@ -1061,9 +1071,99 @@ public static function regexpMatchEndAnchorCases() { 'REGEXP_REPLACE, second occurrence' => array( "REGEXP_REPLACE('aab', '\\\\Ga', '-', 1, 2)", 'a-b' ), 'REGEXP_REPLACE, in a comment' => array( "REGEXP_REPLACE('aa', '(?#\\\\G)a', 'x', 2)", 'ax' ), 'REGEXP_REPLACE, escaped backslash' => array( "REGEXP_REPLACE('a\\\\Gb', '\\\\\\\\G', '-', 2)", 'a-b' ), + + 'REGEXP_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' ), ); } + /** + * @dataProvider regexpSubstrCases + */ + public function testRegexpSubstr( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpSubstrCases() { + return array( + 'basic match' => array( "REGEXP_SUBSTR('abc123def', '[0-9]+')", '123' ), + 'no match' => array( "REGEXP_SUBSTR('abcdef', '[0-9]+')", null ), + 'pos' => array( "REGEXP_SUBSTR('abc123def456', '[0-9]+', 5)", '23' ), + 'pos with occurrence=2' => array( "REGEXP_SUBSTR('abc123def456', '[0-9]+', 5, 2)", '456' ), + 'occurrence' => array( "REGEXP_SUBSTR('a1 b2 c3', '[a-z][0-9]', 1, 2)", 'b2' ), + 'occurrence too high' => array( "REGEXP_SUBSTR('a1 b2', '[a-z][0-9]', 1, 5)", null ), + 'match_type c' => array( "REGEXP_SUBSTR('ABC', 'abc', 1, 1, 'c')", null ), + 'multibyte match' => array( "REGEXP_SUBSTR('café', 'é')", 'é' ), + // MySQL allows pos = char_count + 1. + 'pos one past end' => array( "REGEXP_SUBSTR('abc', 'a', 4)", null ), + 'zero-width at end' => array( "REGEXP_SUBSTR('abc', '\$', 4)", '' ), + 'null expr' => array( 'REGEXP_SUBSTR(NULL, \'abc\')', null ), + 'null pattern' => array( "REGEXP_SUBSTR('abc', NULL)", null ), + 'null pos' => array( "REGEXP_SUBSTR('abc', 'a', NULL)", null ), + 'null occurrence' => array( "REGEXP_SUBSTR('abc', 'a', 1, NULL)", null ), + 'null match_type' => array( "REGEXP_SUBSTR('abc', 'a', 1, 1, NULL)", null ), + // A NULL match_type returns NULL before the pattern and pos are checked. + 'null match_type first' => array( "REGEXP_SUBSTR('abc', '(abc', 0, 1, NULL)", null ), + // A NULL occurrence returns NULL before pos is checked. + 'null occurrence, pos 0' => array( "REGEXP_SUBSTR('abc', 'a', 0, NULL)", null ), + ); + } + + /** + * @dataProvider regexpSubstrErrors + */ + public function testRegexpSubstrErrors( $sql, $message ) { + $this->assertQueryError( "SELECT $sql", $message ); + } + + 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 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' ), + 'pos zero' => array( "REGEXP_SUBSTR('abc', 'a', 0)", $pos_error ), + 'pos negative' => array( "REGEXP_SUBSTR('abc', 'a', -1)", $pos_error ), + '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.' ), + 'extra argument' => array( + "REGEXP_SUBSTR('abc', 'a', 1, 1, 'c', 'extra')", + 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_SUBSTR()', + ), + ); + } + + public function testRegexpSubstrOccurrenceClampedToOne() { + // MySQL clamps occurrence <= 0 to 1. + $this->assertQuery( "SELECT REGEXP_SUBSTR('abcabc', 'b', 1, 0) AS r" ); + $this->assertSame( 'b', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_SUBSTR('abcabc', 'b', 1, -5) AS r" ); + $this->assertSame( 'b', $this->last_result[0]->r ); + } + + public function testRegexpSubstrLookbehindAcrossPos() { + // The lookbehind sees bytes before pos because the full subject is kept. + $this->assertQuery( "SELECT REGEXP_SUBSTR('ab', '(?<=a)b', 2) AS r" ); + $this->assertSame( 'b', $this->last_result[0]->r ); + } + + public function testRegexpSubstrNumericSubject() { + $this->assertQuery( "SELECT REGEXP_SUBSTR(123, '2') AS r" ); + $this->assertSame( '2', $this->last_result[0]->r ); + } + /** * @dataProvider regexpBigIntegerCases */ @@ -1081,6 +1181,8 @@ public static function regexpBigIntegerCases() { 'REGEXP_LIKE subject' => array( "REGEXP_LIKE(9999999999, '^9')", '1' ), 'REGEXP_LIKE pattern' => array( "REGEXP_LIKE('9999999999', 9999999999)", '1' ), + 'REGEXP_SUBSTR' => array( "REGEXP_SUBSTR(9999999999, '9+')", '9999999999' ), + 'REGEXP_SUBSTR regex' => array( "REGEXP_SUBSTR('9999999999', 9999999999)", '9999999999' ), 'REGEXP_REPLACE' => array( "REGEXP_REPLACE(9999999999, '9', '1')", '1111111111' ), 'REGEXP_REPLACE regex' => array( "REGEXP_REPLACE('9999999999', 9999999999, 'x')", 'x' ), 'replacement' => array( "REGEXP_REPLACE('a', 'a', 9999999999)", '9999999999' ), @@ -1098,7 +1200,8 @@ public function testRegexpBigIntegerColumn() { "SELECT phone REGEXP '^1' AS operator_result, REGEXP_LIKE(phone, '^1') AS like_result, - REGEXP_REPLACE(phone, '^1', '') AS replace_result + REGEXP_REPLACE(phone, '^1', '') AS replace_result, + REGEXP_SUBSTR(phone, '^[0-9]{3}') AS substr_result FROM phones ORDER BY id" ); $this->assertEquals( @@ -1107,16 +1210,19 @@ public function testRegexpBigIntegerColumn() { 'operator_result' => '1', 'like_result' => '1', 'replace_result' => '5551234567', + 'substr_result' => '155', ), (object) array( 'operator_result' => '0', 'like_result' => '0', 'replace_result' => '42', + 'substr_result' => null, ), (object) array( 'operator_result' => null, 'like_result' => null, 'replace_result' => null, + 'substr_result' => null, ), ), $this->last_result 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 64a169cbc..ae48e3237 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 @@ -8,7 +8,998 @@ class WP_MySQL_On_SQLite_Regexp_Substr_Tests extends WP_MySQL_On_SQLite_Regexp_Test_Case { const CHECKS = array( 'regexp_substr' ); - protected function setUp(): void { - $this->markTestSkipped( 'REGEXP_SUBSTR() is not supported yet.' ); + 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: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', + 'icu-regextst:524', + 'icu-regextst:525', + 'icu-regextst:538', + 'icu-regextst:539', + 'icu-regextst:540', + 'icu-regextst:541', + 'icu-regextst:542', + 'icu-regextst:543', + 'icu-regextst:544', + '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', + 'icu-regextst:1226', + 'icu-regextst:1227', + 'icu-regextst:1228', + 'icu-regextst:1231', + 'icu-regextst:1232', + 'icu-regextst:1239', + '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', + 'icu-regextst:1252', + 'icu-regextst:1253', + 'icu-regextst:1254', + 'icu-regextst:1255', + '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', + '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', + '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: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( + $failures, + 'mysql-server-suite:12583', + 'mysql-server-suite:12584' + ); + } + + // 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( + $failures, + 'mysql-server-suite:6471', + 'mysql-server-suite:6472' + ); + } + + // 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; } } From 683366e6260bddba5783693f9c8aa963dd10ccc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Thu, 12 Nov 2026 12:42:46 +0100 Subject: [PATCH 4/5] Add REGEXP_INSTR() UDF Implement MySQL's REGEXP_INSTR(expr, pattern [, pos [, occurrence [, return_option [, match_type]]]]). It returns the character position of a match, or of the character after it when return_option is 1, and 0 when there is no such match. Like in MySQL: - The search starts in the subject from pos on, so "^" matches at pos, and lookbehind doesn't see the text before it. - pos can't be one past the end, unlike in REGEXP_SUBSTR() and REGEXP_REPLACE(), but it isn't checked for an empty subject, where a match is reported at pos. - An invalid return_option is an error even when another argument is NULL. In data that is not valid UTF-8, positions count bytes. --- .../src/sqlite/class-wp-mysql-on-sqlite.php | 1 + ...s-wp-sqlite-pdo-user-defined-functions.php | 72 +- .../tests/WP_MySQL_On_SQLite_Tests.php | 149 ++- .../WP_MySQL_On_SQLite_Regexp_Instr_Tests.php | 995 +++++++++++++++++- 4 files changed, 1210 insertions(+), 7 deletions(-) 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 d142e3d50..0e954a7ab 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 @@ -5397,6 +5397,7 @@ private function translate_function_call( WP_Parser_Node $node ): string { return $this->quote_sqlite_value( $this->get_mysql_server_version_string() ); case 'REGEXP_LIKE': case 'REGEXP_SUBSTR': + case 'REGEXP_INSTR': case 'REGEXP_REPLACE': // PDO narrows integer UDF arguments to 32 bits, so pass the subject, the // pattern, and REGEXP_REPLACE's replacement as text. 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 cad531a60..91b40dea6 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 @@ -67,6 +67,7 @@ public static function register_for( $pdo ): self { 'regexp_like' => 'regexp_like', 'regexp_replace' => 'regexp_replace', 'regexp_substr' => 'regexp_substr', + 'regexp_instr' => 'regexp_instr', 'field' => 'field', 'log' => 'log', 'least' => 'least', @@ -104,6 +105,7 @@ public static function register_for( $pdo ): self { 'regexp_like' => array( 2, 3 ), 'regexp_replace' => array( 3, 4, 5, 6 ), 'regexp_substr' => array( 2, 3, 4, 5 ), + 'regexp_instr' => array( 2, 3, 4, 5, 6 ), ); /** @var string[] Compiled PCRE patterns, keyed by byte mode, "\G" variant, match type, and pattern. */ @@ -764,6 +766,72 @@ public function regexp_substr( $expr, $pattern, $pos = 1, $occurrence = 1, $matc return null === $match ? null : $match[0][0]; } + /** + * Method to emulate MySQL REGEXP_INSTR() function. + * + * Unlike the other functions, it searches the subject from pos on, as if it started + * there. So "^" and "\G" match at pos, and lookbehinds don't see the text before it. + * + * @param string|null $expr The subject string. + * @param string|null $pattern The regex pattern. + * @param int|float|string|null $pos Optional. The 1-based character position to start at. + * It isn't checked for an empty subject. + * @param int|float|string|null $occurrence Optional. Which match to find. A value below 1 + * finds the first match. + * @param int|float|string|null $return_option Optional. 0 for the position of the match, or 1 + * for the position after it. + * @param string|null $match_type Optional. Letters that change how the pattern matches. + * + * @throws Exception If return_option is not 0 or 1, the match type has an unknown + * letter, the pattern is invalid, or pos is out of range. + * @return int|null The 1-based character position, 0 if there is no match, or NULL if + * any argument is NULL. + */ + public function regexp_instr( $expr, $pattern, $pos = 1, $occurrence = 1, $return_option = 0, $match_type = '' ) { + // Like MySQL, check the arguments in this order, so that a NULL argument makes + // the result NULL only when the checks before it pass. + if ( null !== $return_option && 0 !== (int) $return_option && 1 !== (int) $return_option ) { + throw new Exception( 'Incorrect arguments to regexp_instr: return_option must be 1 or 0.' ); + } + $this->regexp_check_match_type( 'regexp_instr', $match_type ); + if ( null === $match_type ) { + return null; + } + + // Like REGEXP_LIKE(), match data that is not valid UTF-8 byte by byte. + $byte_mode = ! $this->regexp_is_utf8( $pattern ) || ! $this->regexp_is_utf8( $expr ); + $match_type = $byte_mode ? 'c' . $match_type : $match_type; + if ( null !== $pattern ) { + $this->regexp_compile( $pattern, $match_type, $byte_mode ); + } + if ( null === $expr || null === $pattern || null === $pos || null === $occurrence || null === $return_option ) { + return null; + } + + // MySQL doesn't check pos for an empty subject, and reports its matches at pos. + if ( '' === $expr ) { + $match = $this->regexp_find_match( $pattern, $match_type, $byte_mode, '', 0, (int) $occurrence ); + return null === $match ? 0 : (int) $pos; + } + + $byte_start = $this->regexp_char_to_byte_offset( $expr, (int) $pos, false, $byte_mode ); + $match = $this->regexp_find_match( $pattern, $match_type, $byte_mode, substr( $expr, $byte_start ), 0, (int) $occurrence ); + if ( null === $match ) { + return 0; + } + + $byte_offset = $byte_start + $match[0][1]; + if ( 1 === (int) $return_option ) { + $byte_offset += strlen( $match[0][0] ); + } + if ( $byte_mode ) { + return $byte_offset + 1; + } + + // Every byte except a UTF-8 continuation byte starts a character. + return $byte_offset + 1 - preg_match_all( '/[\x80-\xBF]/', substr( $expr, 0, $byte_offset ) ); + } + /** * Method to emulate MySQL FIELD() function. * @@ -1184,8 +1252,8 @@ private function regexp_check_match_type( $function_name, $match_type ) { * sensitivity, and whether positions count bytes, can differ between rows. * - SQLite converts numbers to text in its own format, so `20e0` reads "20.0" * (MySQL: "20"), and `0.000001` reads "1.0e-06". - * - `pos` and `occurrence` use PHP's integer conversion, so `2.6` means 2 - * (MySQL: 3), and `'2e1'` means 20 (MySQL: 2). + * - `pos`, `occurrence`, and `return_option` use PHP's integer conversion, so + * `2.6` means 2 (MySQL: 3), and `'2e1'` means 20 (MySQL: 2). * - A repeated group, like `(a|b)*`, can exceed PCRE's limits on a subject of * about 50,000 characters, or 2,000 on PHP 7.2. * 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 f128469ef..4434d1aee 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 @@ -393,6 +393,14 @@ public static function regexpBinaryDataCases() { 'REGEXP_SUBSTR, pos one past end' => array( "X'C485FF'", "REGEXP_SUBSTR(b, 'x*', 4)", '' ), 'REGEXP_SUBSTR, occurrence' => array( "X'C485FF'", "REGEXP_SUBSTR(b, '.', 1, 3)", "\xFF" ), 'REGEXP_SUBSTR, empty matches' => array( "X'C485FF'", "REGEXP_SUBSTR(b, 'x*', 1, 4)", '' ), + + 'REGEXP_INSTR, other case' => array( "X'61FF41'", "REGEXP_INSTR(b, 'A')", '3' ), + 'REGEXP_INSTR, ignore case' => array( "X'61FF41'", "REGEXP_INSTR(b, 'A', 1, 1, 0, 'i')", '1' ), + 'REGEXP_INSTR, position' => array( "X'C485FF61'", "REGEXP_INSTR(b, 'a')", '4' ), + 'REGEXP_INSTR, end position' => array( "X'C485FF61'", "REGEXP_INSTR(b, '.\$', 1, 1, 1)", '5' ), + 'REGEXP_INSTR, pos' => array( "X'C485FF61'", "REGEXP_INSTR(b, '^.', 2)", '2' ), + 'REGEXP_INSTR, occurrence' => array( "X'C485FF'", "REGEXP_INSTR(b, '.', 1, 3)", '3' ), + 'REGEXP_INSTR, empty matches' => array( "X'C485FF'", "REGEXP_INSTR(b, 'x*', 1, 3)", '3' ), ); } @@ -445,7 +453,8 @@ public function testRegexpJitStackLimit() { "SELECT '$subject' REGEXP '^(a|b)*\$' AS operator_result, REGEXP_LIKE('$subject', '^(a|b)*\$') AS like_result, - LENGTH(REGEXP_SUBSTR('$subject', '(a|b)+')) AS substr_length" + LENGTH(REGEXP_SUBSTR('$subject', '(a|b)+')) AS substr_length, + REGEXP_INSTR('$subject', '(a|b)+\$', 1, 1, 1) AS instr_result" ); $this->assertEquals( array( @@ -453,6 +462,7 @@ public function testRegexpJitStackLimit() { 'operator_result' => '1', 'like_result' => '1', 'substr_length' => '20000', + 'instr_result' => '20001', ), ), $this->last_result @@ -537,7 +547,8 @@ public function testRegexpNulBytePattern() { s REGEXP p AS matched, s NOT REGEXP p AS not_matched, s REGEXP BINARY p AS binary_matched, - REGEXP_LIKE(s, p) AS like_matched + REGEXP_LIKE(s, p) AS like_matched, + REGEXP_INSTR(s, p) AS position FROM nul_patterns ORDER BY id' ); $this->assertEquals( @@ -547,30 +558,35 @@ public function testRegexpNulBytePattern() { 'not_matched' => '0', 'binary_matched' => '0', 'like_matched' => '1', + 'position' => '2', ), (object) array( 'matched' => '0', 'not_matched' => '1', 'binary_matched' => '0', 'like_matched' => '0', + 'position' => '0', ), (object) array( 'matched' => '1', 'not_matched' => '0', 'binary_matched' => '0', 'like_matched' => '1', + 'position' => '2', ), (object) array( 'matched' => '1', 'not_matched' => '0', 'binary_matched' => '1', 'like_matched' => '1', + 'position' => '1', ), (object) array( 'matched' => '1', 'not_matched' => '0', 'binary_matched' => '0', 'like_matched' => '1', + 'position' => '1', ), ), $this->last_result @@ -1076,6 +1092,12 @@ public static function regexpMatchEndAnchorCases() { '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' ), ); } @@ -1164,6 +1186,121 @@ public function testRegexpSubstrNumericSubject() { $this->assertSame( '2', $this->last_result[0]->r ); } + /** + * @dataProvider regexpInstrCases + */ + public function testRegexpInstr( $sql, $expected ) { + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpInstrCases() { + return array( + 'basic' => array( "REGEXP_INSTR('dog cat dog', 'dog')", '1' ), + 'no match' => array( "REGEXP_INSTR('abc', 'xyz')", '0' ), + 'second match' => array( "REGEXP_INSTR('dog cat dog', 'dog', 1, 2)", '9' ), + 'pos skips first match' => array( "REGEXP_INSTR('dog cat dog', 'dog', 5)", '9' ), + 'return_option=1 (end)' => array( "REGEXP_INSTR('dog cat dog', 'dog', 1, 1, 1)", '4' ), + 'match_type c miss' => array( "REGEXP_INSTR('DOG', 'dog', 1, 1, 0, 'c')", '0' ), + 'multibyte position' => array( "REGEXP_INSTR('café123', '[0-9]+')", '5' ), + 'null expr' => array( "REGEXP_INSTR(NULL, 'abc')", null ), + 'null pattern' => array( "REGEXP_INSTR('abc', NULL)", null ), + // A NULL match_type returns NULL before the pattern and pos are checked. + 'null match_type first' => array( "REGEXP_INSTR('abc', '(abc', 0, 1, 0, NULL)", null ), + // NULL arguments return NULL before pos is checked. + 'null expr, pos 0' => array( "REGEXP_INSTR(NULL, 'a', 0)", null ), + 'null expr, pos -1' => array( "REGEXP_INSTR(NULL, 'a', -1)", null ), + 'null expr, pos 5' => array( "REGEXP_INSTR(NULL, 'a', 5)", null ), + 'null pattern, pos 0' => array( "REGEXP_INSTR('abc', NULL, 0)", null ), + 'null occurrence, pos 0' => array( "REGEXP_INSTR('abc', 'a', 0, NULL)", null ), + ); + } + + /** + * @dataProvider regexpInstrErrors + */ + public function testRegexpInstrErrors( $sql, $message ) { + $this->assertQueryError( "SELECT $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.' ), + // 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 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.' ), + // 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.' ), + '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 ), + 'invalid return_option and match type' => array( "REGEXP_INSTR('abc', 'a', 1, 1, 2, 'x')", $return_option ), + 'extra argument' => array( + "REGEXP_INSTR('abc', 'a', 1, 1, 0, 'c', 'extra')", + 'SQLSTATE[HY000]: General error: 1 wrong number of arguments to function REGEXP_INSTR()', + ), + ); + } + + public function testRegexpInstrEmptySubjectSkipsPosCheck() { + // MySQL does not check pos for an empty subject and reports a match at pos. + $cases = array( + "'a', 2" => '0', + "'^', 5" => '5', + "'^', -3" => '-3', + ); + foreach ( $cases as $args => $expected ) { + $this->assertQuery( "SELECT REGEXP_INSTR('', $args) AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r, $args ); + } + + $this->assertQueryError( + "SELECT REGEXP_INSTR('', '(', 2)", + 'Invalid regular expression: (.' + ); + } + + public function testRegexpInstrOccurrenceClampedToOne() { + // MySQL clamps occurrence <= 0 to 1. + $this->assertQuery( "SELECT REGEXP_INSTR('abcabc', 'b', 1, 0) AS r" ); + $this->assertSame( '2', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_INSTR('abcabc', 'b', 1, -5) AS r" ); + $this->assertSame( '2', $this->last_result[0]->r ); + } + + public function testRegexpInstrStraddlingMatch() { + // A match that starts before pos is not returned; the next match at or + // after pos is returned instead. + $this->assertQuery( "SELECT REGEXP_INSTR('abc123def', '[0-9]+', 5) AS r" ); + $this->assertSame( '5', $this->last_result[0]->r ); + } + + public function testRegexpInstrMultibyteReturnOptionEnd() { + // Multibyte match ('é' is 2 bytes) with return_option=1 (one past end). + // 'aéb' char positions: a=1, é=2, b=3. 'é' matches at char 2, end char position = 3. + $this->assertQuery( "SELECT REGEXP_INSTR('aéb', 'é', 1, 1, 1) AS r" ); + $this->assertSame( '3', $this->last_result[0]->r ); + } + + public function testRegexpInstrPatternIsRelativeToPos() { + $this->assertQuery( "SELECT REGEXP_INSTR('abc', '^b', 2) AS r" ); + $this->assertSame( '2', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_INSTR('ab', '(?<=a)b', 2) AS r" ); + $this->assertSame( '0', $this->last_result[0]->r ); + } + + public function testRegexpInstrNumericSubject() { + $this->assertQuery( "SELECT REGEXP_INSTR(123, '2') AS r" ); + $this->assertSame( '2', $this->last_result[0]->r ); + } + /** * @dataProvider regexpBigIntegerCases */ @@ -1183,6 +1320,8 @@ public static function regexpBigIntegerCases() { 'REGEXP_LIKE pattern' => array( "REGEXP_LIKE('9999999999', 9999999999)", '1' ), 'REGEXP_SUBSTR' => array( "REGEXP_SUBSTR(9999999999, '9+')", '9999999999' ), 'REGEXP_SUBSTR regex' => array( "REGEXP_SUBSTR('9999999999', 9999999999)", '9999999999' ), + 'REGEXP_INSTR' => array( "REGEXP_INSTR(9999999999, '99', 1, 2)", '3' ), + 'REGEXP_INSTR pattern' => array( "REGEXP_INSTR('x9999999999', 9999999999)", '2' ), 'REGEXP_REPLACE' => array( "REGEXP_REPLACE(9999999999, '9', '1')", '1111111111' ), 'REGEXP_REPLACE regex' => array( "REGEXP_REPLACE('9999999999', 9999999999, 'x')", 'x' ), 'replacement' => array( "REGEXP_REPLACE('a', 'a', 9999999999)", '9999999999' ), @@ -1201,7 +1340,8 @@ public function testRegexpBigIntegerColumn() { phone REGEXP '^1' AS operator_result, REGEXP_LIKE(phone, '^1') AS like_result, REGEXP_REPLACE(phone, '^1', '') AS replace_result, - REGEXP_SUBSTR(phone, '^[0-9]{3}') AS substr_result + REGEXP_SUBSTR(phone, '^[0-9]{3}') AS substr_result, + REGEXP_INSTR(phone, '4') AS instr_result FROM phones ORDER BY id" ); $this->assertEquals( @@ -1211,18 +1351,21 @@ public function testRegexpBigIntegerColumn() { 'like_result' => '1', 'replace_result' => '5551234567', 'substr_result' => '155', + 'instr_result' => '8', ), (object) array( 'operator_result' => '0', 'like_result' => '0', 'replace_result' => '42', 'substr_result' => null, + 'instr_result' => '1', ), (object) array( 'operator_result' => null, 'like_result' => null, 'replace_result' => null, 'substr_result' => null, + 'instr_result' => null, ), ), $this->last_result 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 67e0ef6e4..64f1c94c6 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 @@ -8,7 +8,998 @@ class WP_MySQL_On_SQLite_Regexp_Instr_Tests extends WP_MySQL_On_SQLite_Regexp_Test_Case { const CHECKS = array( 'regexp_instr', 'regexp_instr_end' ); - protected function setUp(): void { - $this->markTestSkipped( 'REGEXP_INSTR() is not supported yet.' ); + 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: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', + 'icu-regextst:524', + 'icu-regextst:525', + 'icu-regextst:538', + 'icu-regextst:539', + 'icu-regextst:540', + 'icu-regextst:541', + 'icu-regextst:542', + 'icu-regextst:543', + 'icu-regextst:544', + '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', + 'icu-regextst:1226', + 'icu-regextst:1227', + 'icu-regextst:1228', + 'icu-regextst:1231', + 'icu-regextst:1232', + 'icu-regextst:1239', + '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', + 'icu-regextst:1252', + 'icu-regextst:1253', + 'icu-regextst:1254', + 'icu-regextst:1255', + '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', + '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', + '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: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( + $failures, + 'mysql-server-suite:12583', + 'mysql-server-suite:12584' + ); + } + + // 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( + $failures, + 'mysql-server-suite:6471', + 'mysql-server-suite:6472' + ); + } + + // 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; } } From 0693bbddd4efa277cfaabda225b02b7c3cf2ae70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Thu, 12 Nov 2026 12:43:06 +0100 Subject: [PATCH 5/5] Pin down REGEXP_* edge cases shared across functions Test behavior that all four REGEXP_* functions share: - They work on table columns in SELECT, WHERE, and UPDATE statements. - An empty pattern is an error. - A 4-byte UTF-8 character counts as one character. - Zero-width matches step forward one character, like in ICU. --- .../tests/WP_MySQL_On_SQLite_Tests.php | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) 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 4434d1aee..615959486 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 @@ -266,6 +266,63 @@ public static function regexpOperators() { ); } + public function testRegexpFunctionsWithTableColumns() { + $this->assertQuery( + "INSERT INTO _options (option_name, option_value) VALUES + ('test-ignore', 'unchanged'), + ('test-remove', 'unchanged'), + ('keep', 'unchanged');" + ); + + $this->assertQuery( + "SELECT + option_name, + REGEXP_REPLACE(option_name, '(-ignore|-remove)\$', '') AS replacement_result, + REGEXP_SUBSTR(option_name, '[^-]+\$') AS substring_result, + REGEXP_INSTR(option_name, '-') AS position_result + FROM _options + WHERE REGEXP_LIKE(option_name, '^test-') + ORDER BY option_name" + ); + $this->assertEquals( + array( + (object) array( + 'option_name' => 'test-ignore', + 'replacement_result' => 'test', + 'substring_result' => 'ignore', + 'position_result' => '5', + ), + (object) array( + 'option_name' => 'test-remove', + 'replacement_result' => 'test', + 'substring_result' => 'remove', + 'position_result' => '5', + ), + ), + $this->last_result + ); + + $this->assertQuery( + "UPDATE _options + SET option_value = REGEXP_REPLACE(option_name, '^test-', '') + WHERE REGEXP_LIKE(option_name, '^test-')" + ); + $this->assertQuery( "SELECT option_name, option_value FROM _options WHERE option_value != 'unchanged' ORDER BY option_name" ); + $this->assertEquals( + array( + (object) array( + 'option_name' => 'test-ignore', + 'option_value' => 'ignore', + ), + (object) array( + 'option_name' => 'test-remove', + 'option_value' => 'remove', + ), + ), + $this->last_result + ); + } + /** * @dataProvider regexpLikeQueries */ @@ -1301,6 +1358,118 @@ public function testRegexpInstrNumericSubject() { $this->assertSame( '2', $this->last_result[0]->r ); } + public function testRegexpEmptyPatternRejected() { + // MySQL rejects the empty pattern with ERROR 3685. + $this->assertQueryError( + "SELECT REGEXP_LIKE('abc', '')", + 'Illegal argument to a regular expression.' + ); + $this->assertQueryError( + "SELECT REGEXP_REPLACE('abc', '', 'x')", + 'Illegal argument to a regular expression.' + ); + $this->assertQueryError( + "SELECT REGEXP_SUBSTR('abc', '')", + 'Illegal argument to a regular expression.' + ); + $this->assertQueryError( + "SELECT REGEXP_INSTR('abc', '')", + 'Illegal argument to a regular expression.' + ); + } + + /** + * @dataProvider regexpEmptyMatchSteppingCases + */ + public function testRegexpEmptyMatchStepping( $sql, $expected ) { + // Like in ICU, the search continues one character after an empty match, even + // when the pattern could match a non-empty string at the same position. + $this->assertQuery( "SELECT $sql AS r" ); + $this->assertSame( $expected, $this->last_result[0]->r ); + } + + public static function regexpEmptyMatchSteppingCases() { + return array( + 'lazy star' => array( "REGEXP_REPLACE('aaa', 'a*?', '[\$0]')", '[]a[]a[]a[]' ), + 'lazy optional' => array( "REGEXP_REPLACE('aaa', 'a??', '[\$0]')", '[]a[]a[]a[]' ), + 'empty alternative first' => array( "REGEXP_REPLACE('aaa', '|a', '[\$0]')", '[]a[]a[]a[]' ), + 'boundary alternative' => array( "REGEXP_REPLACE('ab', '\\\\b|a', '[\$0]')", '[]ab[]' ), + 'anchor alternative' => array( "REGEXP_REPLACE('abc', '^|b', '[\$0]')", '[]a[b]c' ), + 'lookahead alternative' => array( "REGEXP_REPLACE('ab', '(?=b)|a', '[\$0]')", '[a][]b' ), + 'greedy, ends with empty' => array( "REGEXP_REPLACE('aaa', 'a*', '[\$0]')", '[aaa][]' ), + 'greedy, starts with empty' => array( "REGEXP_REPLACE('baaa', 'a*', '[\$0]')", '[]b[aaa][]' ), + 'multibyte character' => array( "REGEXP_REPLACE('éa', 'a*?', '[\$0]')", '[]é[]a[]' ), + 'astral character' => array( "REGEXP_REPLACE('a😀b', 'x*', '[\$0]')", '[]a[]😀[]b[]' ), + 'replace second' => array( "REGEXP_REPLACE('aaa', 'a*?', '[\$0]', 1, 2)", 'a[]aa' ), + 'replace past the matches' => array( "REGEXP_REPLACE('ab', '\\\\b|a', '[\$0]', 1, 3)", 'ab' ), + 'substr, empty match' => array( "REGEXP_SUBSTR('aaa', 'a*?', 1, 2)", '' ), + 'substr, one past the end' => array( "REGEXP_SUBSTR('aaa', 'a*?', 1, 4)", '' ), + 'substr, after an empty' => array( "REGEXP_SUBSTR('baaa', 'a*', 1, 2)", 'aaa' ), + 'substr, no more matches' => array( "REGEXP_SUBSTR('aaa', 'a*', 1, 3)", null ), + 'instr, empty match' => array( "REGEXP_INSTR('aaa', 'a*?', 1, 3)", '3' ), + 'instr, boundary' => array( "REGEXP_INSTR('ab', '\\\\b|a', 1, 2)", '3' ), + 'instr, astral character' => array( "REGEXP_INSTR('a😀b', 'x*', 1, 3)", '3' ), + 'instr, no more matches' => array( "REGEXP_INSTR('aaa', 'a*', 1, 3)", '0' ), + ); + } + + public function testRegexpAstralPlaneCharacter() { + // 4-byte UTF-8 encodes as one code point; char offsets should reflect that. + // "x😀y" has three characters (x at 1, 😀 at 2, y at 3). + $this->assertQuery( "SELECT REGEXP_SUBSTR('x😀y', '.', 2) AS r" ); + $this->assertSame( '😀', $this->last_result[0]->r ); + $this->assertQuery( "SELECT REGEXP_INSTR('😀z', 'z', 1, 1, 1) AS r" ); + $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 */