Skip to content

Commit 4d69bbe

Browse files
committed
Fixed bug #76437 (token_get_all with TOKEN_PARSE flag fails to recognise close tag)
1 parent 24f7096 commit 4d69bbe

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ PHP NEWS
2727
`!(zval_gc_flags((str)->gc)). (Nikita, Laruence)
2828

2929
- Tokenizer:
30+
. Fixed bug #76437 (token_get_all with TOKEN_PARSE flag fails to recognise
31+
close tag). (Laruence)
3032
. Fixed bug #75218 (Change remaining uncatchable fatal errors for parsing
3133
into ParseError). (Nikita)
3234

ext/tokenizer/tests/bug76437.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #76437 (token_get_all with TOKEN_PARSE flag fails to recognise close tag)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$open_tag1 = token_get_all('<?=$a?>')[0];
8+
$open_tag2 = token_get_all('<?=$a?>', TOKEN_PARSE)[0];
9+
var_dump($open_tag1);
10+
var_dump($open_tag1 === $open_tag2);
11+
$open_tag1 = token_get_all('<?php echo 2; ?>')[6];
12+
$open_tag2 = token_get_all('<?php echo 2; ?>', TOKEN_PARSE)[6];
13+
var_dump($open_tag1);
14+
var_dump($open_tag1 === $open_tag2);
15+
?>
16+
--EXPECT--
17+
array(3) {
18+
[0]=>
19+
int(380)
20+
[1]=>
21+
string(3) "<?="
22+
[2]=>
23+
int(1)
24+
}
25+
bool(true)
26+
array(3) {
27+
[0]=>
28+
int(381)
29+
[1]=>
30+
string(2) "?>"
31+
[2]=>
32+
int(1)
33+
}
34+
bool(true)

ext/tokenizer/tokenizer.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,16 @@ void on_event(zend_php_scanner_event event, int token, int line, void *context)
191191

192192
switch (event) {
193193
case ON_TOKEN:
194-
if (token == END) break;
195-
add_token(token_stream, token, LANG_SCNG(yy_text), LANG_SCNG(yy_leng), line);
194+
{
195+
if (token == END) break;
196+
/* Specical cases */
197+
if (token == ';' && LANG_SCNG(yy_leng) == sizeof("?>") - 1) {
198+
token = T_CLOSE_TAG;
199+
} else if (token == T_ECHO && LANG_SCNG(yy_leng) == sizeof("<?=") - 1) {
200+
token = T_OPEN_TAG_WITH_ECHO;
201+
}
202+
add_token(token_stream, token, LANG_SCNG(yy_text), LANG_SCNG(yy_leng), line);
203+
}
196204
break;
197205
case ON_FEEDBACK:
198206
tokens_ht = Z_ARRVAL_P(token_stream);

0 commit comments

Comments
 (0)