summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--ext/tokenizer/tests/bug76437.phpt29
-rw-r--r--ext/tokenizer/tokenizer.c2
3 files changed, 26 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index a9f8ae656d..02bb055932 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,10 @@ PHP NEWS
. Fixed bug #76505 (array_merge_recursive() is duplicating sub-array keys).
(Laruence)
+- Tokenizer:
+ . Fixed bug #76538 (token_get_all with TOKEN_PARSE flag fails to recognise
+ close tag with newline). (Nikita)
+
21 Jun 2018, PHP 7.3.0alpha2
- Core:
diff --git a/ext/tokenizer/tests/bug76437.phpt b/ext/tokenizer/tests/bug76437.phpt
index 4a979db710..348c9bdc00 100644
--- a/ext/tokenizer/tests/bug76437.phpt
+++ b/ext/tokenizer/tests/bug76437.phpt
@@ -4,14 +4,17 @@ Bug #76437 (token_get_all with TOKEN_PARSE flag fails to recognise close tag)
<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
--FILE--
<?php
-$open_tag1 = token_get_all('<?=$a?>')[0];
-$open_tag2 = token_get_all('<?=$a?>', TOKEN_PARSE)[0];
-var_dump($open_tag1);
-var_dump($open_tag1 === $open_tag2);
-$open_tag1 = token_get_all('<?php echo 2; ?>')[6];
-$open_tag2 = token_get_all('<?php echo 2; ?>', TOKEN_PARSE)[6];
-var_dump($open_tag1);
-var_dump($open_tag1 === $open_tag2);
+$tests = [
+ ['<?=$a?>', 0],
+ ['<?php echo 2; ?>', 6],
+ ["<?php echo 2; ?>\n", 6],
+];
+foreach ($tests as [$code, $index]) {
+ $open_tag1 = token_get_all($code)[$index];
+ $open_tag2 = token_get_all($code, TOKEN_PARSE)[$index];
+ var_dump($open_tag1);
+ var_dump($open_tag1 === $open_tag2);
+}
?>
--EXPECT--
array(3) {
@@ -32,3 +35,13 @@ array(3) {
int(1)
}
bool(true)
+array(3) {
+ [0]=>
+ int(381)
+ [1]=>
+ string(3) "?>
+"
+ [2]=>
+ int(1)
+}
+bool(true)
diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c
index 66d6ba7262..58b271ef4b 100644
--- a/ext/tokenizer/tokenizer.c
+++ b/ext/tokenizer/tokenizer.c
@@ -194,7 +194,7 @@ void on_event(zend_php_scanner_event event, int token, int line, void *context)
{
if (token == END) break;
/* Special cases */
- if (token == ';' && LANG_SCNG(yy_leng) == sizeof("?>") - 1) {
+ if (token == ';' && LANG_SCNG(yy_leng) > 1) { /* <? or <?\n or <?\r\n */
token = T_CLOSE_TAG;
} else if (token == T_ECHO && LANG_SCNG(yy_leng) == sizeof("<?=") - 1) {
token = T_OPEN_TAG_WITH_ECHO;