diff --git a/ChangeLog b/ChangeLog index be04231cea..76d38d5eba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -47,6 +47,7 @@ phpMyAdmin - ChangeLog - issue Fix colspan for actions column on database table list - issue Fix double encoding on User Groups pages - issue Fix list of users of an user group not showing up +- issue Fix duplicate query params in the SQL message card 5.2.1 (2023-02-07) - issue #17522 Fix case where the routes cache file is invalid diff --git a/libraries/classes/Html/Generator.php b/libraries/classes/Html/Generator.php index 5d822ea526..dbf524a098 100644 --- a/libraries/classes/Html/Generator.php +++ b/libraries/classes/Html/Generator.php @@ -527,12 +527,12 @@ class Generator $urlParams['db'] = $GLOBALS['db']; if (strlen($GLOBALS['table']) > 0) { $urlParams['table'] = $GLOBALS['table']; - $editLink = Url::getFromRoute('/table/sql'); + $editLinkRoute = '/table/sql'; } else { - $editLink = Url::getFromRoute('/database/sql'); + $editLinkRoute = '/database/sql'; } } else { - $editLink = Url::getFromRoute('/server/sql'); + $editLinkRoute = '/server/sql'; } // Want to have the query explained @@ -546,16 +546,16 @@ class Generator $explainParams['sql_query'] = 'EXPLAIN ' . $sqlQuery; $explainLink = ' [ ' . self::linkOrButton( - Url::getFromRoute('/import'), - $explainParams, + Url::getFromRoute('/import', $explainParams), + null, __('Explain SQL'), ) . ' ]'; } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sqlQuery)) { $explainParams['sql_query'] = mb_substr($sqlQuery, 8); $explainLink = ' [ ' . self::linkOrButton( - Url::getFromRoute('/import'), - $explainParams, + Url::getFromRoute('/import', $explainParams), + null, __('Skip Explain SQL'), ) . ']'; } @@ -568,7 +568,7 @@ class Generator // to edit it (unless it's enormous, see linkOrButton() ) if (! empty($GLOBALS['cfg']['SQLQuery']['Edit']) && empty($GLOBALS['show_as_php'])) { $editLink = ' [ ' - . self::linkOrButton($editLink, $urlParams, __('Edit')) + . self::linkOrButton(Url::getFromRoute($editLinkRoute, $urlParams), null, __('Edit')) . ' ]'; } else { $editLink = ''; @@ -580,16 +580,16 @@ class Generator if (! empty($GLOBALS['show_as_php'])) { $phpLink = ' [ ' . self::linkOrButton( - Url::getFromRoute('/import'), - $urlParams, + Url::getFromRoute('/import', $urlParams), + null, __('Without PHP code'), ) . ' ]'; $phpLink .= ' [ ' . self::linkOrButton( - Url::getFromRoute('/import'), - $urlParams, + Url::getFromRoute('/import', $urlParams), + null, __('Submit query'), ) . ' ]'; @@ -598,8 +598,8 @@ class Generator $phpParams['show_as_php'] = 1; $phpLink = ' [ ' . self::linkOrButton( - Url::getFromRoute('/import'), - $phpParams, + Url::getFromRoute('/import', $phpParams), + null, __('Create PHP code'), ) . ' ]'; @@ -616,7 +616,7 @@ class Generator ) { $refreshLink = Url::getFromRoute('/sql', $urlParams); $refreshLink = ' [ ' - . self::linkOrButton($refreshLink, $urlParams, __('Refresh')) . ' ]'; + . self::linkOrButton($refreshLink, null, __('Refresh')) . ' ]'; } else { $refreshLink = ''; } diff --git a/test/classes/Html/GeneratorTest.php b/test/classes/Html/GeneratorTest.php index 430fe138a7..e60da79126 100644 --- a/test/classes/Html/GeneratorTest.php +++ b/test/classes/Html/GeneratorTest.php @@ -6,9 +6,12 @@ namespace PhpMyAdmin\Tests\Html; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Message; use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\DbiDummy; use PhpMyAdmin\Types; use PhpMyAdmin\Util; +use PhpMyAdmin\Utils\SessionCache; use function __; use function _pgettext; @@ -433,4 +436,70 @@ class GeneratorTest extends AbstractTestCase [['True_Type' => '', 'first_timestamp' => false, 'Key' => 'PRI', 'Type' => 'char(36)'], true, 'UUID'], ]; } + + public function testGetMessage(): void + { + $GLOBALS['cfg']['ShowSQL'] = true; + $GLOBALS['display_query'] = null; + $GLOBALS['unparsed_sql'] = null; + $GLOBALS['sql_query'] = 'SELECT 1;'; + $usingBookmarkMessage = Message::notice('Bookmark message'); + $GLOBALS['using_bookmark_message'] = $usingBookmarkMessage; + $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $GLOBALS['server'] = 2; + $GLOBALS['special_message'] = 'Message [em]two[/em].'; + SessionCache::set('profiling_supported', true); + + // phpcs:disable Generic.Files.LineLength.TooLong + $expected = <<<'HTML' + +
+
+SELECT 1;
+
Edit inline ] [ Edit ] [ Explain SQL ] [ Create PHP code ] [ Refresh ]
+HTML; + // phpcs:enable + + $this->assertSame($expected, Generator::getMessage('Message [em]one[/em].')); + $this->assertArrayNotHasKey('using_bookmark_message', $GLOBALS); + $this->assertArrayNotHasKey('special_message', $GLOBALS); + SessionCache::remove('profiling_supported'); + } + + public function testGetMessage2(): void + { + $GLOBALS['cfg']['ShowSQL'] = true; + $GLOBALS['cfg']['SQLQuery']['Edit'] = false; + $GLOBALS['cfg']['SQLQuery']['Refresh'] = true; + $GLOBALS['display_query'] = 'EXPLAIN SELECT 1;'; + $GLOBALS['unparsed_sql'] = null; + $GLOBALS['sql_query'] = null; + $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $GLOBALS['server'] = 2; + $GLOBALS['show_as_php'] = true; + $GLOBALS['special_message'] = 'Message [em]two[/em].'; + SessionCache::set('profiling_supported', true); + + // phpcs:disable Generic.Files.LineLength.TooLong + $expected = <<<'HTML' +
+ +
+$sql = "EXPLAIN SELECT 1;";
+
Skip Explain SQL] [ Without PHP code ] [ Submit query ]
+HTML; + // phpcs:enable + + $this->assertSame($expected, Generator::getMessage(Message::success('Message [em]one[/em].'))); + $this->assertArrayNotHasKey('special_message', $GLOBALS); + SessionCache::remove('profiling_supported'); + } }