Skip to content

Commit 1d984a7

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #54089 (token_get_all() does not stop after __halt_compiler).
1 parent e65d361 commit 1d984a7

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

ext/tokenizer/tests/bug54089.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #54089 (token_get_all() does not stop after __halt_compiler)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("tokenizer")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$code = "<?php __halt_compiler();\x01?>\x02";
8+
$tokens = token_get_all($code);
9+
10+
var_dump($tokens);
11+
12+
$code = '';
13+
foreach ($tokens as $t)
14+
{
15+
$code .= isset($t[1]) ? $t[1] : $t;
16+
}
17+
var_dump($code);
18+
?>
19+
--EXPECTF--
20+
array(2) {
21+
[0]=>
22+
array(3) {
23+
[0]=>
24+
int(%d)
25+
[1]=>
26+
string(6) "<?php "
27+
[2]=>
28+
int(1)
29+
}
30+
[1]=>
31+
array(3) {
32+
[0]=>
33+
int(%d)
34+
[1]=>
35+
string(15) "__halt_compiler"
36+
[2]=>
37+
int(1)
38+
}
39+
}
40+
string(21) "<?php __halt_compiler"

ext/tokenizer/tests/token_get_all_variation16.phpt

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ echo "Done"
5555
?>
5656
--EXPECTF--
5757
*** Testing token_get_all() : with different function constructs ***
58-
array(142) {
58+
array(135) {
5959
[0]=>
6060
array(3) {
6161
[0]=>
@@ -114,11 +114,11 @@ array(142) {
114114
[9]=>
115115
array(3) {
116116
[0]=>
117-
int(262)
117+
int(%d)
118118
[1]=>
119119
string(7) "include"
120120
[2]=>
121-
int(%d)
121+
int(3)
122122
}
123123
[10]=>
124124
string(1) "("
@@ -129,7 +129,7 @@ array(142) {
129129
[1]=>
130130
string(13) ""addfile.php""
131131
[2]=>
132-
int(%d)
132+
int(3)
133133
}
134134
[12]=>
135135
string(1) ")"
@@ -143,12 +143,12 @@ array(142) {
143143
string(1) "
144144
"
145145
[2]=>
146-
int(%d)
146+
int(3)
147147
}
148148
[15]=>
149149
array(3) {
150150
[0]=>
151-
int(259)
151+
int(%d)
152152
[1]=>
153153
string(7) "require"
154154
[2]=>
@@ -590,7 +590,7 @@ array(142) {
590590
[79]=>
591591
array(3) {
592592
[0]=>
593-
int(267)
593+
int(%d)
594594
[1]=>
595595
string(3) ">>="
596596
[2]=>
@@ -659,7 +659,7 @@ array(142) {
659659
[88]=>
660660
array(3) {
661661
[0]=>
662-
int(285)
662+
int(%d)
663663
[1]=>
664664
string(2) "<="
665665
[2]=>
@@ -738,7 +738,7 @@ array(142) {
738738
[98]=>
739739
array(3) {
740740
[0]=>
741-
int(266)
741+
int(%d)
742742
[1]=>
743743
string(5) "print"
744744
[2]=>
@@ -889,7 +889,7 @@ array(142) {
889889
[123]=>
890890
array(3) {
891891
[0]=>
892-
int(279)
892+
int(%d)
893893
[1]=>
894894
string(2) "&&"
895895
[2]=>
@@ -960,42 +960,5 @@ array(142) {
960960
[2]=>
961961
int(26)
962962
}
963-
[135]=>
964-
string(1) "("
965-
[136]=>
966-
string(1) ")"
967-
[137]=>
968-
string(1) ";"
969-
[138]=>
970-
array(3) {
971-
[0]=>
972-
int(%d)
973-
[1]=>
974-
string(1) "
975-
"
976-
[2]=>
977-
int(26)
978-
}
979-
[139]=>
980-
string(1) "}"
981-
[140]=>
982-
array(3) {
983-
[0]=>
984-
int(%d)
985-
[1]=>
986-
string(1) "
987-
"
988-
[2]=>
989-
int(27)
990-
}
991-
[141]=>
992-
array(3) {
993-
[0]=>
994-
int(%d)
995-
[1]=>
996-
string(2) "?>"
997-
[2]=>
998-
int(28)
999-
}
1000963
}
1001964
Done

ext/tokenizer/tokenizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ static void tokenize(zval *return_value TSRMLS_DC)
151151
ZVAL_NULL(&token);
152152

153153
token_line = CG(zend_lineno);
154+
155+
if (token_type == T_HALT_COMPILER) {
156+
break;
157+
}
154158
}
155159
}
156160

0 commit comments

Comments
 (0)