]> git.joonet.de Git - adminer.git/commitdiff
Fix importing multiple SQL files not terminated by semicolon
authorJakub Vrana <jakub@vrana.cz>
Mon, 10 Mar 2025 07:33:25 +0000 (08:33 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 10 Mar 2025 08:09:09 +0000 (09:09 +0100)
Inspired by adminneo-org/adminneo#1c08e86.

adminer/include/functions.inc.php
adminer/sql.inc.php
changes.txt

index c1f0a67c1811b9e6587460f61691f0a1ece2999d..0ef1f71c1c27e0a0d8be7208b9d588aa9ca11273 100644 (file)
@@ -728,9 +728,10 @@ function pagination($page, $current) {
 /** Get file contents from $_FILES
 * @param string
 * @param bool
+* @param string
 * @return mixed int for error, string otherwise
 */
-function get_file($key, $decompress = false) {
+function get_file($key, $decompress = false, $delimiter = "") {
        $file = $_FILES[$key];
        if (!$file) {
                return null;
@@ -752,17 +753,17 @@ function get_file($key, $decompress = false) {
                ); //! may not be reachable because of open_basedir
                if ($decompress) {
                        $start = substr($content, 0, 3);
-                       if (function_exists("iconv") && preg_match("~^\xFE\xFF|^\xFF\xFE~", $start, $regs)) { // not ternary operator to save memory
+                       if (function_exists("iconv") && preg_match("~^\xFE\xFF|^\xFF\xFE~", $start)) { // not ternary operator to save memory
                                $content = iconv("utf-16", "utf-8", $content);
                        } elseif ($start == "\xEF\xBB\xBF") { // UTF-8 BOM
                                $content = substr($content, 3);
                        }
-                       $return .= $content . "\n\n";
-               } else {
-                       $return .= $content;
+               }
+               $return .= $content;
+               if ($delimiter) {
+                       $return .= (preg_match("($delimiter\\s*\$)", $content) ? "" : $delimiter) . "\n\n";
                }
        }
-       //! support SQL files not ending with semicolon
        return $return;
 }
 
index 593cd63f753d626b27c29361bf421cc30636ae69..088be1a04f6c1a98aed67f3ba1abcf75650c5aa2 100644 (file)
@@ -30,7 +30,7 @@ if (!$error && $_POST) {
                ), "rb");
                $query = ($fp ? fread($fp, 1e6) : false);
        } else {
-               $query = get_file("sql_file", true);
+               $query = get_file("sql_file", true, ";");
        }
 
        if (is_string($query)) { // get_file() returns error as number, fread() as false
index 4ac4d2f7877d906536bbd338464a4c0f73e9020f..a5e20bb998190f82778b28ccdd8879ba74f67219 100644 (file)
@@ -1,4 +1,5 @@
 Adminer dev:
+Fix importing multiple SQL files not terminated by semicolon
 
 Adminer 5.0.2 (released 2025-03-10):
 PostgreSQL: Fix setting NULL and original value on enum (bug #884)