Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-19 21:51:12 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-07-19 21:51:12 +0300
commitcba9b38a2865b1a351a46b4117a4cff106abb2ac (patch)
treea9a0d387ee3489f17c2e184386cf25dfe85c220b
parentd631f2fc3dc051da31c6f3961a2523d1b0b360c3 (diff)
parent987cb5043dba8d385a4890bb171a5bf58bcd10ed (diff)
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r--ChangeLog1
-rw-r--r--libraries/classes/Controllers/Table/FindReplaceController.php21
-rw-r--r--psalm-baseline.xml3
-rw-r--r--test/classes/Controllers/Table/FindReplaceControllerTest.php20
4 files changed, 37 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 795bf3dad5..0351f8d4a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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);
+ }
}