Visitar URL original
Merge branch 'QA_5_2' · phpmyadmin/phpmyadmin@cba9b38 · GitHub
Skip to content

Commit cba9b38

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents d631f2f + 987cb50 commit cba9b38

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎ChangeLog‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ phpMyAdmin - ChangeLog
2323
- issue Some languages are now correctly detected from the HTTP header
2424
- issue #17617 Sorting is correctly remembered when $cfg['RememberSorting'] is true
2525
- issue #17593 Table filtering now works when action buttons are on the right side of the row
26+
- issue #17388 Find and Replace using regex now makes a valid query if no matching result set found
2627

2728
5.2.0 (2022-05-10)
2829
- issue #16521 Upgrade Bootstrap to version 5

‎libraries/classes/Controllers/Table/FindReplaceController.php‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,24 @@ public function replace(
321321
if ($useRegex) {
322322
$toReplace = $this->getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet);
323323
$sql_query = 'UPDATE ' . Util::backquote($GLOBALS['table'])
324-
. ' SET ' . Util::backquote($column) . ' = CASE';
324+
. ' SET ' . Util::backquote($column);
325+
325326
if (is_array($toReplace)) {
326-
foreach ($toReplace as $row) {
327-
$sql_query .= "\n WHEN " . Util::backquote($column)
328-
. " = '" . $this->dbi->escapeString($row[0])
329-
. "' THEN '" . $this->dbi->escapeString($row[1]) . "'";
327+
if (count($toReplace) > 0) {
328+
$sql_query .= ' = CASE';
329+
foreach ($toReplace as $row) {
330+
$sql_query .= "\n WHEN " . Util::backquote($column)
331+
. " = '" . $this->dbi->escapeString($row[0])
332+
. "' THEN '" . $this->dbi->escapeString($row[1]) . "'";
333+
}
334+
335+
$sql_query .= ' END';
336+
} else {
337+
$sql_query .= ' = ' . Util::backquote($column);
330338
}
331339
}
332340

333-
$sql_query .= ' END'
334-
. ' WHERE ' . Util::backquote($column)
341+
$sql_query .= ' WHERE ' . Util::backquote($column)
335342
. " RLIKE '" . $this->dbi->escapeString($find) . "' COLLATE "
336343
. $charSet . '_bin'; // here we
337344
// change the collation of the 2nd operand to a case sensitive

‎psalm-baseline.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,7 @@
33283328
</MixedAssignment>
33293329
</file>
33303330
<file src="libraries/classes/Controllers/Table/FindReplaceController.php">
3331-
<MixedArgument occurrences="26">
3331+
<MixedArgument occurrences="27">
33323332
<code>$_POST['columnIndex']</code>
33333333
<code>$_POST['columnIndex']</code>
33343334
<code>$_POST['find']</code>
@@ -3351,6 +3351,7 @@
33513351
<code>$column</code>
33523352
<code>$column</code>
33533353
<code>$column</code>
3354+
<code>$column</code>
33543355
<code>$column_types[$i]</code>
33553356
<code>$row[0]</code>
33563357
<code>$row[0]</code>

‎test/classes/Controllers/Table/FindReplaceControllerTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,24 @@ public function testReplace(): void
9090
. "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin";
9191
$this->assertEquals($result, $sql_query);
9292
}
93+
94+
public function testReplaceWithRegex(): void
95+
{
96+
$tableSearch = new FindReplaceController(ResponseRenderer::getInstance(), new Template(), $GLOBALS['dbi']);
97+
98+
$columnIndex = 0;
99+
$find = 'Field';
100+
$replaceWith = 'Column';
101+
$useRegex = true;
102+
$charSet = 'UTF-8';
103+
104+
$tableSearch->replace($columnIndex, $find, $replaceWith, $useRegex, $charSet);
105+
106+
$sql_query = $GLOBALS['sql_query'];
107+
108+
$result = 'UPDATE `table` SET `Field1` = `Field1`'
109+
. " WHERE `Field1` RLIKE 'Field' COLLATE UTF-8_bin";
110+
111+
$this->assertEquals($result, $sql_query);
112+
}
93113
}

0 commit comments

Comments
 (0)