From 48a8dae59d716ee7c18922496b8d8b58fcd5a3e4 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 6 Apr 2024 18:19:47 +0200 Subject: [PATCH] Fix truncated SQL in "Create PHP code" Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 2 +- src/Html/Generator.php | 22 +++------------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b1c38b9e72..7870359059 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8342,7 +8342,7 @@ parameters: - message: "#^Parameter \\#1 \\$string of function mb_substr expects string, mixed given\\.$#" - count: 2 + count: 1 path: src/Html/Generator.php - diff --git a/src/Html/Generator.php b/src/Html/Generator.php index 75b81a8fda..dff1d8aece 100644 --- a/src/Html/Generator.php +++ b/src/Html/Generator.php @@ -455,34 +455,19 @@ class Generator $retval .= ' ' . $message->getMessage() . "\n"; $retval .= '' . "\n"; - $queryTooBig = false; - - $queryLength = mb_strlen($sqlQuery); - if ($queryLength > $config->settings['MaxCharactersInDisplayedSQL']) { - // when the query is large (for example an INSERT of binary - // data), the parser chokes; so avoid parsing the query - $queryTooBig = true; - $queryBase = mb_substr($sqlQuery, 0, $config->settings['MaxCharactersInDisplayedSQL']) . '[...]'; - } else { - $queryBase = $sqlQuery; - } - // Html format the query to be displayed // If we want to show some sql code it is easiest to create it here /* SQL-Parser-Analyzer */ if (! empty($GLOBALS['show_as_php'])) { $newLine = '\\n"
' . "\n" . '    . "'; - $queryBase = htmlspecialchars(addslashes($queryBase)); + $queryBase = htmlspecialchars(addslashes($sqlQuery)); $queryBase = preg_replace('/((\015\012)|(\015)|(\012))/', $newLine, $queryBase); $queryBase = '
' . "\n"
                 . '$sql = "' . $queryBase . '";' . "\n"
                 . '
'; - } elseif ($queryTooBig) { - $queryBase = '
' . "\n"
-                . htmlspecialchars($queryBase, ENT_COMPAT) . '
'; } else { - $queryBase = self::formatSql($queryBase); + $queryBase = self::formatSql($sqlQuery, true); } // Prepares links that may be displayed to edit/explain the query @@ -507,6 +492,7 @@ class Generator // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ $explainLink = ''; + $queryTooBig = mb_strlen($sqlQuery) > $config->settings['MaxCharactersInDisplayedSQL']; $isSelect = preg_match('@^SELECT[[:space:]]+@i', $sqlQuery); if (! empty($config->settings['SQLQuery']['Explain']) && ! $queryTooBig) { $explainParams = $urlParams; @@ -1085,8 +1071,6 @@ class Generator * @param bool $truncate truncate the query if it is too long * * @return string the formatted sql - * - * @global array $cfg the configuration array */ public static function formatSql(string $sqlQuery, bool $truncate = false): string {