From 33397adc99024f85feef7d1baf9eecdc489dcd15 Mon Sep 17 00:00:00 2001 From: Robert Chipperfield Date: Thu, 28 Mar 2019 11:32:40 +0000 Subject: [PATCH 1/3] Allow whitespace after FIND_IN_SET function --- wp-includes/translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-includes/translations.php b/wp-includes/translations.php index b0e3c1e21..db18be0d6 100644 --- a/wp-includes/translations.php +++ b/wp-includes/translations.php @@ -1142,7 +1142,7 @@ function translate_findinset($query) && (stripos($query,'UPDATE') !== 0 && stripos($query,'UPDATE') !== FALSE) ) { return $query; } - $pattern = "/FIND_IN_SET\((.*),(.*)\)/"; + $pattern = "/FIND_IN_SET\\s*\((.*),(.*)\)/"; $matched = preg_match($pattern, $query, $matches); if ( $matched == 0 ) { return $query; From 0bdf536ff0591c03a94628194ed490ab4237aca9 Mon Sep 17 00:00:00 2001 From: Robert Chipperfield Date: Thu, 28 Mar 2019 11:33:24 +0000 Subject: [PATCH 2/3] PATINDEX requires % around _pattern_ https://docs.microsoft.com/en-us/sql/t-sql/functions/patindex-transact-sql --- wp-includes/translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-includes/translations.php b/wp-includes/translations.php index db18be0d6..ee8bc307e 100644 --- a/wp-includes/translations.php +++ b/wp-includes/translations.php @@ -1148,7 +1148,7 @@ function translate_findinset($query) return $query; } // Replace the FIND_IN_SET - $query = preg_replace($pattern, "PATINDEX(','+" . $matches[1] . "+',', ','+" . $matches[2] . "+',')", $query); + $query = preg_replace($pattern, "PATINDEX('%,'+" . $matches[1] . "+',%', ','+" . $matches[2] . "+',')", $query); return $query; } From 3ce5bc090dc1afd5fab2d0c973eec8144266f94b Mon Sep 17 00:00:00 2001 From: Robert Chipperfield Date: Thu, 28 Mar 2019 12:34:52 +0000 Subject: [PATCH 3/3] Escape %s since we're going back via vsprintf --- wp-includes/translations.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/translations.php b/wp-includes/translations.php index ee8bc307e..4626164f1 100644 --- a/wp-includes/translations.php +++ b/wp-includes/translations.php @@ -1147,8 +1147,13 @@ function translate_findinset($query) if ( $matched == 0 ) { return $query; } + // Replace the FIND_IN_SET - $query = preg_replace($pattern, "PATINDEX('%,'+" . $matches[1] . "+',%', ','+" . $matches[2] . "+',')", $query); + + // Note: the double percents here are because the result is going to go back via vsprintf, + // and we need it to not look like a replacement token there. Assumption: !empty($this->preg_data) + // holds true, which it should because FIND_IN_SET should originally have taken a string pattern. + $query = preg_replace($pattern, "PATINDEX('%%,'+" . $matches[1] . "+',%%', ','+" . $matches[2] . "+',')", $query); return $query; }