]> git.joonet.de Git - adminer.git/commitdiff
Greedy expressions
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 10 Jul 2007 18:53:35 +0000 (18:53 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 10 Jul 2007 18:53:35 +0000 (18:53 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@105 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
_lang.php
call.inc.php
create.inc.php
database.inc.php
functions.inc.php
index.php
sql.inc.php

index 4193a35ff4c38299ad5d228b000e27ab997d3feb..4c0be778e6f2826f584d0887e22eb17cb9face51 100644 (file)
@@ -49,7 +49,7 @@ if ($_SESSION["lang"]) {
 }
 $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
 if ($_SESSION["lang"]) {
-       $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']*|\\\\.)+)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
+       $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
        $file = str_replace("<?php switch_lang(); ?>\n", "", $file);
        $file = str_replace("<?php echo get_lang(); ?>", $_SESSION["lang"], $file);
 }
index e3279d61ab763109998395604b7687f995d52b85..c928909fadc48b0aadd406d810a9090cdebfcb0d 100644 (file)
--- a/_lang.php
+++ b/_lang.php
@@ -7,7 +7,7 @@ if ($_SERVER["argc"] > 1) {
 $messages_all = array();
 foreach (glob("*.php") as $filename) {
        $file = file_get_contents($filename);
-       if (preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')([),])~", $file, $matches)) {
+       if (preg_match_all("~lang\\(('(?:[^\\\\']+|\\\\.)*')([),])~", $file, $matches)) {
                $messages_all += array_combine($matches[1], $matches[2]);
        }
 }
@@ -16,7 +16,7 @@ $file = file_get_contents("lang.inc.php");
 preg_match_all("~\n\t\t'(.*)' => array\\(\n(.*\n)\t\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
 foreach (array_reverse($translations[2], true) as $key => $translation) {
        $messages = $messages_all;
-       preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']*|\\\\.)+') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
+       preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']+|\\\\.)*') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
        $s = "";
        foreach ($matches as $match) {
                if (isset($messages[$match[3]])) {
index 772802fad5300f3956bd9fd6c4ba6ff8984b0fa3..34863c6df36a5ef94b0c7910bbaada389db95d3c 100644 (file)
@@ -5,8 +5,7 @@ function normalize_enum($match) {
        return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'";
 }
 
-$length = '\'(?:\'\'|[^\'\\\\]*|\\\\.)+\'|"(?:""|[^"\\\\]*|\\\\.)+"';
-$pattern = "\\s*(IN|OUT|INOUT)?\\s*(?:`((?:[^`]*|``)+)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$length)+)\\))?\\s*(?:zerofill\\s+)?(unsigned)?";
+$pattern = "\\s*(IN|OUT|INOUT)?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(?:zerofill\\s+)?(unsigned)?";
 $create = $mysql->result($mysql->query("SHOW CREATE " . (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE") . " " . idf_escape($_GET["call"])), 0, 2);
 preg_match("~\\($pattern(?:\\s*,$pattern)*~is", $create, $match);
 $in = array();
@@ -17,7 +16,7 @@ foreach ($matches as $i => $match) {
        $field = array(
                "field" => str_replace("``", "`", $match[2]) . $match[3],
                "type" => $match[4], //! type aliases
-               "length" => preg_replace_callback("~$length~s", 'normalize_enum', $match[5]),
+               "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $match[5]),
                "unsigned" => ($match[6] ? "unsigned" : ""), // zerofill ignored
                "null" => true,
        );
index 9a0e7630d6b0fb8ff4d806f65c90f4a69ecc6c4c..f9b07f037575484439236cfa815ffc91d8f70ada 100644 (file)
@@ -23,12 +23,11 @@ if ($_POST && !$error && !$_POST["add"]) {
                $fields = array();
                ksort($_POST["fields"]);
                $after = "FIRST";
-               $length = '\'(?:\'\'|[^\'\\\\]*|\\\\.)+\'|"(?:""|[^"\\\\]*|\\\\.)+"';
                foreach ($_POST["fields"] as $key => $field) {
                        if (strlen($field["field"]) && isset($types[$field["type"]])) {
                                $fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD "))
                                        . idf_escape($field["field"]) . " $field[type]"
-                                       . ($field["length"] ? "(" . (preg_match("~^\\s*(?:$length)(?:\\s*,\\s*(?:$length))*\\s*\$~", $field["length"]) && preg_match_all("~$length~", $field["length"], $matches) ? implode(",", $matches[0]) : intval($field["length"])) . ")" : "")
+                                       . ($field["length"] ? "(" . (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $field["length"]) && preg_match_all("~$enum_length~", $field["length"], $matches) ? implode(",", $matches[0]) : intval($field["length"])) . ")" : "")
                                        . (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
                                        . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " COLLATE '" . $mysql->escape_string($field["collation"]) . "'" : "")
                                        . ($field["null"] ? "" : " NOT NULL")
index d63a8f87069aa0a357613bf3864be9c49d05121f..d3538e1ec1b45b25c020b184ec1ea0c82041ae8f 100644 (file)
@@ -2,12 +2,12 @@
 if ($_POST && !$error) {
        if ($_POST["drop"]) {
                if ($mysql->query("DROP DATABASE " . idf_escape($_GET["db"]))) {
-                       redirect(substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF), 0, -1), lang('Database has been dropped.'));
+                       redirect(substr(preg_replace('~db=[^&]*&~', '', $SELF), 0, -1), lang('Database has been dropped.'));
                }
        } elseif ($_GET["db"] !== $_POST["name"]) {
                if ($mysql->query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'" : ""))) {
                        if (!strlen($_GET["db"])) {
-                               redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
+                               redirect(preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
                        }
                        $result = $mysql->query("SHOW TABLES");
                        while ($row = $result->fetch_row()) {
@@ -18,7 +18,7 @@ if ($_POST && !$error) {
                        $result->free();
                        if (!$row) {
                                $mysql->query("DROP DATABASE " . idf_escape($_GET["db"]));
-                               redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
+                               redirect(preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
                        }
                }
        } elseif (!$_POST["collation"] || $mysql->query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'")) {
index 14b847593815522a29be96b33a851f67dd086d9a..56bd91ed703254d0c03b6b9dce5463574bcc30fe 100644 (file)
@@ -68,7 +68,7 @@ function indexes($table) {
 
 function foreign_keys($table) {
        global $mysql;
-       static $pattern = '~`((?:[^`]*|``)+)`~';
+       static $pattern = '~`((?:[^`]+|``)*)`~';
        $return = array();
        $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
        if ($result) {
@@ -255,7 +255,7 @@ function input($name, $field, $value) {
                if (!isset($_GET["default"])) {
                        echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value === 0 ? ' checked="checked"' : '') . ' />';
                }
-               preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
+               preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
                foreach ($matches[1] as $i => $val) {
                        $val = stripcslashes(str_replace("''", "'", $val));
                        $id = "field-$name-" . ($i+1);
@@ -267,7 +267,7 @@ function input($name, $field, $value) {
                        echo ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (strlen($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
                }
        } elseif ($field["type"] == "set") { //! 64 bits
-               preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
+               preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
                foreach ($matches[1] as $i => $val) {
                        $val = stripcslashes(str_replace("''", "'", $val));
                        $id = "field-$name-" . ($i+1);
index c11dd0c1372cfbdf692ed9fcd0bcc09850d61d45..84189e8d1c0b8c2c1bd4ed7dfab88dbd0059cef1 100644 (file)
--- a/index.php
+++ b/index.php
@@ -28,6 +28,7 @@ if (isset($_GET["dump"])) {
                        $error = (in_array($_POST["token"], (array) $TOKENS) ? "" : lang('Invalid CSRF token. Send the form again.'));
                }
                $token = ($_POST && !$error ? $_POST["token"] : token());
+               $enum_length = '\'(?:\'\'|[^\'\\\\]+|\\\\.)*\'|"(?:""|[^"\\\\]+|\\\\.)*"';
                if (isset($_GET["default"])) {
                        $_GET["edit"] = $_GET["default"];
                }
index c2e1f6c66f3a85ccb94b02d64c4ebb0d4225e2d6..2bdc66556dd2f8d948dc41a573ba4a65203828ac 100644 (file)
@@ -13,7 +13,7 @@ if ($_POST && $error) {
                        $query = substr($query, strlen($match[0]));
                } elseif (preg_match("~$delimiter|['`\"]|\$~", $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
                        if ($match[0][0] && $match[0][0] != $delimiter) {
-                               preg_match('~\\G([^\\\\' . $match[0][0] . ']*|\\\\.)+(' . $match[0][0] . '|$)~s', $query, $match, PREG_OFFSET_CAPTURE, $match[0][1] + 1);
+                               preg_match('~\\G([^\\\\' . $match[0][0] . ']+|\\\\.)*(' . $match[0][0] . '|$)~s', $query, $match, PREG_OFFSET_CAPTURE, $match[0][1] + 1);
                                $offset = $match[0][1] + strlen($match[0][0]);
                        } else {
                                $empty = false;