]> granicus.if.org Git - php/commitdiff
Fixed bug #78604
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Sep 2019 08:41:14 +0000 (10:41 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Sep 2019 08:41:14 +0000 (10:41 +0200)
<?php followed by EOF is valid since PHP 7.4.

NEWS
Zend/zend_language_scanner.l
ext/tokenizer/tests/php_tag_only.phpt
ext/tokenizer/tests/php_tag_only_2.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9e0e0cbc5f5b94a237f3682fac54dee983a58a36..4f46995c4e56accc4e3335f35442ce51ec6caaf7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 7.4.0RC3
 
+- Core:
+  . Fixed bug #78604 (token_get_all() does not properly tokenize FOO<?php with
+    short_open_tag=0). (Nikita)
+
 - FFI:
   . Fixed bug #78543 (is_callable() on FFI\CData throws Exception). (cmb)
 
index bfe71705b95aa92969d3221c6c7d9dee6a0c3014..ba692c184b4c9a4f2818220804700af9c4d86aa8 100644 (file)
@@ -2057,7 +2057,8 @@ inline_char_handler:
                        if (CG(short_tags) /* <? */
                                || (*(YYCURSOR + 1) == '=') /* <?= */
                                || (!strncasecmp((char*)YYCURSOR + 1, "php", 3) && /* <?php[ \t\r\n] */
-                                       (YYCURSOR[4] == ' ' || YYCURSOR[4] == '\t' ||
+                                       (YYCURSOR + 4 == YYLIMIT ||
+                                       YYCURSOR[4] == ' ' || YYCURSOR[4] == '\t' ||
                                        YYCURSOR[4] == '\n' || YYCURSOR[4] == '\r'))
                        ) {
                                YYCURSOR--;
index aec11f9e16c13059adaa2f8cfa883f8892b670a8..3d51e0cea55a816a27b946a23d717b22f17a3e86 100644 (file)
@@ -2,6 +2,8 @@
 Tokenization of only the <?php tag
 --SKIPIF--
 <?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?>
+--INI--
+short_open_tag=1
 --FILE--
 <?php
 
diff --git a/ext/tokenizer/tests/php_tag_only_2.phpt b/ext/tokenizer/tests/php_tag_only_2.phpt
new file mode 100644 (file)
index 0000000..60e4004
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Tokenization of only the <?php tag
+--SKIPIF--
+<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?>
+--INI--
+short_open_tag=0
+--FILE--
+<?php
+
+foreach (token_get_all("<?php") as $token) {
+    echo token_name($token[0]), "\n";
+}
+echo "\n";
+foreach (token_get_all("Foobar<?php") as $token) {
+    echo token_name($token[0]), "\n";
+}
+
+?>
+--EXPECT--
+T_OPEN_TAG
+
+T_INLINE_HTML
+T_OPEN_TAG