From c6f825a786b4a10766af8e58e3430d2d96241072 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 6 Mar 2025 14:51:24 +0100 Subject: [PATCH] Move $enum_length to Driver --- adminer/drivers/mysql.inc.php | 6 +++--- adminer/include/bootstrap.inc.php | 2 +- adminer/include/driver.inc.php | 1 + adminer/include/editing.inc.php | 4 ++-- adminer/index.php | 2 -- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1a3d765e..9b9aefae 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -955,10 +955,10 @@ if (!defined("DRIVER")) { * @return array ["fields" => ["field" => , "type" => , "length" => , "unsigned" => , "inout" => , "collation" => ], "returns" => , "definition" => , "language" => ] */ function routine($name, $type) { - global $connection, $enum_length, $driver; + global $connection, $driver; $aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar"); $space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)"; - $type_pattern = "((" . implode("|", array_merge(array_keys($driver->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum_length)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?"; + $type_pattern = "((" . implode("|", array_merge(array_keys($driver->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$driver->enumLength)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?"; $pattern = "$space*(" . ($type == "FUNCTION" ? "" : $driver->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern"; $create = $connection->result("SHOW CREATE $type " . idf_escape($name), 2); preg_match("~\\(((?:$pattern\\s*,?)*)\\)\\s*" . ($type == "FUNCTION" ? "RETURNS\\s+$type_pattern\\s+" : "") . "(.*)~is", $create, $match); @@ -968,7 +968,7 @@ if (!defined("DRIVER")) { $fields[] = array( "field" => str_replace("``", "`", $param[2]) . $param[3], "type" => strtolower($param[5]), - "length" => preg_replace_callback("~$enum_length~s", 'Adminer\normalize_enum', $param[6]), + "length" => preg_replace_callback("~$driver->enumLength~s", 'Adminer\normalize_enum', $param[6]), "unsigned" => strtolower(preg_replace('~\s+~', ' ', trim("$param[8] $param[7]"))), "null" => 1, "full_type" => $param[4], diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index f2a57fe5..86a63240 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -35,7 +35,7 @@ if ($_GET["script"] == "version") { exit; } -global $adminer, $connection, $driver, $drivers, $enum_length, $error, $HTTPS, $jush, $LANG, $langs, $permanent, $has_token, $token, $translations, $VERSION; // allows including Adminer inside a function +global $adminer, $connection, $driver, $drivers, $error, $HTTPS, $jush, $LANG, $langs, $permanent, $has_token, $token, $translations, $VERSION; // allows including Adminer inside a function if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility $_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"]; diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 102f118d..0b8bd91b 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -35,6 +35,7 @@ abstract class SqlDriver { var $grouping = array(); ///< @var array grouping functions used in select var $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; ///< @var string used in foreign_keys() var $inout = "IN|OUT|INOUT"; + var $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; /** Create object for performing database operations * @param Db diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index d9686d4e..3d16d35c 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -256,8 +256,8 @@ function get_partitions_info($table) { * @return string */ function process_length($length) { - global $enum_length; - return (preg_match("~^\\s*\\(?\\s*$enum_length(?:\\s*,\\s*$enum_length)*+\\s*\\)?\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) + global $driver; + return (preg_match("~^\\s*\\(?\\s*$driver->enumLength(?:\\s*,\\s*$enum_length)*+\\s*\\)?\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? "(" . implode(",", $matches[0]) . ")" : preg_replace('~^[0-9].*~', '(\0)', preg_replace('~[^-0-9,+()[\]]~', '', $length)) ); diff --git a/adminer/index.php b/adminer/index.php index c2f40800..78065230 100644 --- a/adminer/index.php +++ b/adminer/index.php @@ -12,8 +12,6 @@ namespace Adminer; include "./include/bootstrap.inc.php"; include "./include/tmpfile.inc.php"; -$enum_length = "'(?:''|[^'\\\\]|\\\\.)*'"; - if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) { $_GET["edit"] = $_GET["select"]; }