]> git.joonet.de Git - adminer.git/commitdiff
Don't use \r\n in compiled strings
authorJakub Vrana <jakub@vrana.cz>
Fri, 7 Sep 2012 05:15:03 +0000 (22:15 -0700)
committerJakub Vrana <jakub@vrana.cz>
Fri, 7 Sep 2012 15:37:52 +0000 (08:37 -0700)
adminer/file.inc.php
compile.php

index 332e58fad8e465f51caa61d739e772c8fecd5549..53eafd3601d8c28288f8fbae06704775a2e70740 100644 (file)
@@ -3,21 +3,21 @@ header("Expires: " . gmdate("D, d M Y H:i:s", time() + 365*24*60*60) . " GMT");
 
 if ($_GET["file"] == "favicon.ico") {
        header("Content-Type: image/x-icon");
-       echo 'compile_file("../adminer/static/favicon.ico", "add_apo_slashes");';
+       echo "compile_file('../adminer/static/favicon.ico', 'add_quo_slashes');";
 } elseif ($_GET["file"] == "default.css") {
        header("Content-Type: text/css; charset=utf-8");
-       ?>compile_file("../adminer/static/default.css", "minify_css");<?php
+       ?>compile_file('../adminer/static/default.css', 'minify_css');<?php
 } elseif ($_GET["file"] == "functions.js") {
        header("Content-Type: text/javascript; charset=utf-8");
-       ?>compile_file("../adminer/static/functions.js", "jsShrink");compile_file("static/editing.js", "jsShrink");<?php
+       ?>compile_file('../adminer/static/functions.js', 'jsShrink');compile_file('static/editing.js', 'jsShrink');<?php
 } else {
        header("Content-Type: image/gif");
        switch ($_GET["file"]) {
-               case "plus.gif": echo 'compile_file("../adminer/static/plus.gif", "add_apo_slashes");'; break;
-               case "cross.gif": echo 'compile_file("../adminer/static/cross.gif", "add_apo_slashes");'; break;
-               case "up.gif": echo 'compile_file("../adminer/static/up.gif", "add_apo_slashes");'; break;
-               case "down.gif": echo 'compile_file("../adminer/static/down.gif", "add_apo_slashes");'; break;
-               case "arrow.gif": echo 'compile_file("../adminer/static/arrow.gif", "add_apo_slashes");'; break;
+               case "plus.gif": echo "compile_file('../adminer/static/plus.gif', 'add_quo_slashes');"; break;
+               case "cross.gif": echo "compile_file('../adminer/static/cross.gif', 'add_quo_slashes');"; break;
+               case "up.gif": echo "compile_file('../adminer/static/up.gif', 'add_quo_slashes');"; break;
+               case "down.gif": echo "compile_file('../adminer/static/down.gif', 'add_quo_slashes');"; break;
+               case "arrow.gif": echo "compile_file('../adminer/static/arrow.gif', 'add_quo_slashes');"; break;
        }
 }
 exit;
index e25620410f0606fd5e6f2337257335e6c5fb7e08..c1ed443b3428278a1a22734abc54e03a587fe7a3 100755 (executable)
@@ -14,6 +14,10 @@ function add_apo_slashes($s) {
        return addcslashes($s, "\\'");
 }
 
+function add_quo_slashes($s) {
+       return addcslashes($s, "\n\r\$\"\\");
+}
+
 function remove_lang($match) {
        global $translations;
        $idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
@@ -112,7 +116,8 @@ function put_file_lang($match) {
                                $translation_ids[$lang_ids[$key]] = implode("\t", (array) $val);
                        }
                }
-               $return .= "\n\t\tcase \"$lang\": \$compressed = '" . add_apo_slashes(lzw_compress(implode("\n", $translation_ids))) . "'; break;";
+               $return .= '
+               case "' . $lang . '": $compressed = "' . add_quo_slashes(lzw_compress(implode("\n", $translation_ids))) . '"; break;';
        }
        $translations_version = crc32($return);
        return '$translations = &$_SESSION["translations"];
@@ -202,10 +207,10 @@ function php_shrink($input) {
                        $token = array(0, $token);
                }
                if ($tokens[$i+2][0] === T_CLOSE_TAG && $tokens[$i+3][0] === T_INLINE_HTML && $tokens[$i+4][0] === T_OPEN_TAG
-                       && strlen(addcslashes($tokens[$i+3][1], "'\\")) < strlen($tokens[$i+3][1]) + 3
+                       && strlen(add_apo_slashes($tokens[$i+3][1])) < strlen($tokens[$i+3][1]) + 3
                ) {
                        $tokens[$i+2] = array(T_ECHO, 'echo');
-                       $tokens[$i+3] = array(T_CONSTANT_ENCAPSED_STRING, "'" . addcslashes($tokens[$i+3][1], "'\\") . "'");
+                       $tokens[$i+3] = array(T_CONSTANT_ENCAPSED_STRING, "'" . add_apo_slashes($tokens[$i+3][1]) . "'");
                        $tokens[$i+4] = array(0, ';');
                }
                if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE || ($token[0] == T_DOC_COMMENT && $doc_comment)) {
@@ -328,8 +333,8 @@ foreach (array("adminer", "editor") as $project) {
                }
        }
        $file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
-       $file = str_replace("\r", "", $file);
        $file = preg_replace_callback('~\\b(include|require) "([^"]*\\$LANG.inc.php)";~', 'put_file_lang', $file);
+       $file = str_replace("\r", "", $file);
        if ($_SESSION["lang"]) {
                // single language version
                $file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
@@ -337,7 +342,7 @@ foreach (array("adminer", "editor") as $project) {
                $file = str_replace('<?php echo $LANG; ?>', $_SESSION["lang"], $file);
        }
        $file = str_replace('<script type="text/javascript" src="static/editing.js"></script>' . "\n", "", $file);
-       $file = preg_replace_callback('~compile_file\\("([^"]+)", "([^"]+)"\\);~', 'compile_file', $file); // integrate static files
+       $file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\);~", 'compile_file', $file); // integrate static files
        $replace = 'h(preg_replace("~\\\\\\\\?.*~", "", ME)) . "?file=\\1&amp;version=' . $VERSION;
        $file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
        $file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);