]> git.joonet.de Git - adminer.git/commitdiff
php_shrink: Move add_apo_slashes to compile.php
authorJakub Vrana <jakub@vrana.cz>
Sat, 15 Mar 2025 08:10:43 +0000 (09:10 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sat, 15 Mar 2025 08:10:43 +0000 (09:10 +0100)
compile.php
php_shrink.inc.php
tests/php_shrink.php

index 0585d071113344042e9d9be52db3cf2e7f073c90..47656e90f8d87bd479f51adf16b63df9c1446282 100755 (executable)
@@ -5,6 +5,10 @@ include __DIR__ . "/adminer/include/errors.inc.php";
 include __DIR__ . "/php_shrink.inc.php";
 include __DIR__ . "/externals/JsShrink/jsShrink.php";
 
+function add_apo_slashes($s) {
+       return addcslashes($s, "\\'");
+}
+
 function add_quo_slashes($s) {
        $return = $s;
        $return = addcslashes($return, "\n\r\$\"\\");
index c4e79cfe7c1401dd6f05cab653c1dbb4d378443b..6bc45a12fbc911e143f31e81900ff2b0152f631b 100644 (file)
@@ -55,10 +55,10 @@ function php_shrink($input) {
        foreach ($tokens as $i => $token) {
                if (
                        $tokens[$i+2][0] === T_CLOSE_TAG && $tokens[$i+3][0] === T_INLINE_HTML && $tokens[$i+4][0] === T_OPEN_TAG
-                       && strlen(add_apo_slashes($tokens[$i+3][1])) < strlen($tokens[$i+3][1]) + 3
+                       && strlen(addcslashes($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, "'" . add_apo_slashes($tokens[$i+3][1]) . "'");
+                       $tokens[$i+3] = array(T_CONSTANT_ENCAPSED_STRING, "'" . addcslashes($tokens[$i+3][1], "\\'") . "'");
                        $tokens[$i+4] = array(0, ';');
                }
        }
@@ -140,7 +140,3 @@ function short_identifier($number, $chars) {
        }
        return $return;
 }
-
-function add_apo_slashes($s) {
-       return addcslashes($s, "\\'");
-}
index 41f4cb9cc0468dc7cbd63205460e2ce0c5478494..505245e63a49f6cec4437329e0219df4e0cc3b11 100644 (file)
@@ -13,6 +13,9 @@ function check($code, $expected) {
 //! bugs:
 check('{if (true) {} echo 1;}', '{if(true);echo 1;}');
 
+//! inefficiencies
+check('echo "a"."b",\'c\'."d$a"."e";', 'echo "abcd$a"."e"');
+
 check('$ab = 1; echo $ab;', '$a=1;echo$a;');
 check('$ab = 1; $cd = 2;', '$a=1;$b=2;');
 check('define("AB", 1);', 'define("AB",1);');