diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | libraries/classes/Controllers/Table/FindReplaceController.php | 21 | ||||
-rw-r--r-- | psalm-baseline.xml | 3 | ||||
-rw-r--r-- | test/classes/Controllers/Table/FindReplaceControllerTest.php | 20 |
4 files changed, 37 insertions, 8 deletions
@@ -23,6 +23,7 @@ phpMyAdmin - ChangeLog - issue Some languages are now correctly detected from the HTTP header - issue #17617 Sorting is correctly remembered when $cfg['RememberSorting'] is true - issue #17593 Table filtering now works when action buttons are on the right side of the row +- issue #17388 Find and Replace using regex now makes a valid query if no matching result set found 5.2.0 (2022-05-10) - issue #16521 Upgrade Bootstrap to version 5 diff --git a/libraries/classes/Controllers/Table/FindReplaceController.php b/libraries/classes/Controllers/Table/FindReplaceController.php index 350d906d85..7a03a3d09b 100644 --- a/libraries/classes/Controllers/Table/FindReplaceController.php +++ b/libraries/classes/Controllers/Table/FindReplaceController.php @@ -321,17 +321,24 @@ class FindReplaceController extends AbstractController if ($useRegex) { $toReplace = $this->getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet); $sql_query = 'UPDATE ' . Util::backquote($GLOBALS['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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6bf88aed27..19d34b1304 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3328,7 +3328,7 @@ </MixedAssignment> </file> <file src="libraries/classes/Controllers/Table/FindReplaceController.php"> - <MixedArgument occurrences="26"> + <MixedArgument occurrences="27"> <code>$_POST['columnIndex']</code> <code>$_POST['columnIndex']</code> <code>$_POST['find']</code> @@ -3351,6 +3351,7 @@ <code>$column</code> <code>$column</code> <code>$column</code> + <code>$column</code> <code>$column_types[$i]</code> <code>$row[0]</code> <code>$row[0]</code> diff --git a/test/classes/Controllers/Table/FindReplaceControllerTest.php b/test/classes/Controllers/Table/FindReplaceControllerTest.php index 5646904ce1..d37c1bc476 100644 --- a/test/classes/Controllers/Table/FindReplaceControllerTest.php +++ b/test/classes/Controllers/Table/FindReplaceControllerTest.php @@ -90,4 +90,24 @@ class FindReplaceControllerTest extends AbstractTestCase . "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin"; $this->assertEquals($result, $sql_query); } + + public function testReplaceWithRegex(): void + { + $tableSearch = new FindReplaceController(ResponseRenderer::getInstance(), new Template(), $GLOBALS['dbi']); + + $columnIndex = 0; + $find = 'Field'; + $replaceWith = 'Column'; + $useRegex = true; + $charSet = 'UTF-8'; + + $tableSearch->replace($columnIndex, $find, $replaceWith, $useRegex, $charSet); + + $sql_query = $GLOBALS['sql_query']; + + $result = 'UPDATE `table` SET `Field1` = `Field1`' + . " WHERE `Field1` RLIKE 'Field' COLLATE UTF-8_bin"; + + $this->assertEquals($result, $sql_query); + } } |