diff options
author | Ankush Patil <aspraz2658@gmail.com> | 2022-07-17 17:30:02 +0300 |
---|---|---|
committer | MaurĂcio Meneghini Fauth <mauricio@fauth.dev> | 2022-07-19 21:28:43 +0300 |
commit | 987cb5043dba8d385a4890bb171a5bf58bcd10ed (patch) | |
tree | 311bfaf16e4dcfff55f01a56e7702e57a9ff53d5 /libraries | |
parent | f82e460805b2ac1cfdbd3b877c855a8b539a5334 (diff) |
fixed find replace regex issue if no matching result set found
When find and replace searching used with regex, at the time of replace
empty CASE END condition was causing issue.
Fixes #17388
Closes #17641
Signed-off-by: Ankush Patil <aspraz2658@gmail.com>
Signed-off-by: MaurĂcio Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Controllers/Table/FindReplaceController.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/libraries/classes/Controllers/Table/FindReplaceController.php b/libraries/classes/Controllers/Table/FindReplaceController.php index 68d00b06ae..1f0ec7f360 100644 --- a/libraries/classes/Controllers/Table/FindReplaceController.php +++ b/libraries/classes/Controllers/Table/FindReplaceController.php @@ -324,17 +324,24 @@ class FindReplaceController extends AbstractController if ($useRegex) { $toReplace = $this->getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet); $sql_query = 'UPDATE ' . Util::backquote($this->table) - . ' SET ' . Util::backquote($column) . ' = CASE'; + . ' SET ' . Util::backquote($column); + if (is_array($toReplace)) { - foreach ($toReplace as $row) { - $sql_query .= "\n WHEN " . Util::backquote($column) - . " = '" . $this->dbi->escapeString($row[0]) - . "' THEN '" . $this->dbi->escapeString($row[1]) . "'"; + if (count($toReplace) > 0) { + $sql_query .= ' = CASE'; + foreach ($toReplace as $row) { + $sql_query .= "\n WHEN " . Util::backquote($column) + . " = '" . $this->dbi->escapeString($row[0]) + . "' THEN '" . $this->dbi->escapeString($row[1]) . "'"; + } + + $sql_query .= ' END'; + } else { + $sql_query .= ' = ' . Util::backquote($column); } } - $sql_query .= ' END' - . ' WHERE ' . Util::backquote($column) + $sql_query .= ' WHERE ' . Util::backquote($column) . " RLIKE '" . $this->dbi->escapeString($find) . "' COLLATE " . $charSet . '_bin'; // here we // change the collation of the 2nd operand to a case sensitive |