Skip to content

Commit f3798bb

Browse files
committed
Fix yet another bug
1 parent 117c199 commit f3798bb

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Flexible nowdoc syntax error 6: no ending token on 0 length body
3+
--FILE--
4+
<?php
5+
6+
echo <<<'END'
7+
--EXPECTF--
8+
Parse error: syntax error, unexpected end of file in %s on line %d
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Flexible nowdoc syntax error 7: no ending token
3+
--FILE--
4+
<?php
5+
6+
echo <<<END
7+
8+
--EXPECTF--
9+
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in %s on line %d

Zend/zend_language_scanner.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,7 +3015,7 @@ int start_line = CG(zend_lineno);
30153015
++YYCURSOR;
30163016
YYDEBUG(149, *YYCURSOR);
30173017
yyleng = YYCURSOR - SCNG(yy_text);
3018-
#line 2543 "Zend/zend_language_scanner.l"
3018+
#line 2548 "Zend/zend_language_scanner.l"
30193019
{
30203020
if (YYCURSOR > YYLIMIT) {
30213021
RETURN_TOKEN(END);
@@ -7400,12 +7400,17 @@ int start_line = CG(zend_lineno);
74007400
case '\n':
74017401
indentation = spacing = 0;
74027402

7403-
while (*YYCURSOR == ' ' || *YYCURSOR == '\t') {
7403+
while (YYCURSOR < YYLIMIT && (*YYCURSOR == ' ' || *YYCURSOR == '\t')) {
74047404
spacing |= 1 << (*YYCURSOR == '\t');
74057405
++YYCURSOR;
74067406
++indentation;
74077407
}
74087408

7409+
if (YYCURSOR == YYLIMIT) {
7410+
CG(increment_lineno) = 1;
7411+
RETURN_TOKEN(T_ENCAPSED_AND_WHITESPACE);
7412+
}
7413+
74097414
/* Check for ending label on the next line */
74107415
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
74117416
YYCTYPE *end = YYCURSOR + heredoc_label->length;
@@ -7452,7 +7457,7 @@ int start_line = CG(zend_lineno);
74527457
HANDLE_NEWLINES(yytext, yyleng - newline);
74537458
RETURN_TOKEN(T_ENCAPSED_AND_WHITESPACE);
74547459
}
7455-
#line 7456 "Zend/zend_language_scanner.c"
7460+
#line 7461 "Zend/zend_language_scanner.c"
74567461
/* *********************************** */
74577462
yyc_ST_VAR_OFFSET:
74587463
{
@@ -7572,7 +7577,7 @@ int start_line = CG(zend_lineno);
75727577
}
75737578
RETURN_TOKEN(T_NUM_STRING);
75747579
}
7575-
#line 7576 "Zend/zend_language_scanner.c"
7580+
#line 7581 "Zend/zend_language_scanner.c"
75767581
yy804:
75777582
YYDEBUG(804, *YYCURSOR);
75787583
yych = *++YYCURSOR;
@@ -7597,7 +7602,7 @@ int start_line = CG(zend_lineno);
75977602
/* Only '[' or '-' can be valid, but returning other tokens will allow a more explicit parse error */
75987603
RETURN_TOKEN(yytext[0]);
75997604
}
7600-
#line 7601 "Zend/zend_language_scanner.c"
7605+
#line 7606 "Zend/zend_language_scanner.c"
76017606
yy807:
76027607
YYDEBUG(807, *YYCURSOR);
76037608
++YYCURSOR;
@@ -7608,7 +7613,7 @@ int start_line = CG(zend_lineno);
76087613
yy_pop_state();
76097614
RETURN_TOKEN(']');
76107615
}
7611-
#line 7612 "Zend/zend_language_scanner.c"
7616+
#line 7617 "Zend/zend_language_scanner.c"
76127617
yy809:
76137618
YYDEBUG(809, *YYCURSOR);
76147619
yych = *++YYCURSOR;
@@ -7626,7 +7631,7 @@ int start_line = CG(zend_lineno);
76267631
ZVAL_NULL(zendlval);
76277632
RETURN_TOKEN(T_ENCAPSED_AND_WHITESPACE);
76287633
}
7629-
#line 7630 "Zend/zend_language_scanner.c"
7634+
#line 7635 "Zend/zend_language_scanner.c"
76307635
yy812:
76317636
YYDEBUG(812, *YYCURSOR);
76327637
++YYCURSOR;
@@ -7640,13 +7645,13 @@ int start_line = CG(zend_lineno);
76407645
zend_copy_value(zendlval, yytext, yyleng);
76417646
RETURN_TOKEN(T_STRING);
76427647
}
7643-
#line 7644 "Zend/zend_language_scanner.c"
7648+
#line 7649 "Zend/zend_language_scanner.c"
76447649
yy814:
76457650
YYDEBUG(814, *YYCURSOR);
76467651
++YYCURSOR;
76477652
YYDEBUG(815, *YYCURSOR);
76487653
yyleng = YYCURSOR - SCNG(yy_text);
7649-
#line 2543 "Zend/zend_language_scanner.l"
7654+
#line 2548 "Zend/zend_language_scanner.l"
76507655
{
76517656
if (YYCURSOR > YYLIMIT) {
76527657
RETURN_TOKEN(END);
@@ -7655,7 +7660,7 @@ int start_line = CG(zend_lineno);
76557660
zend_error(E_COMPILE_WARNING,"Unexpected character in input: '%c' (ASCII=%d) state=%d", yytext[0], yytext[0], YYSTATE);
76567661
goto restart;
76577662
}
7658-
#line 7659 "Zend/zend_language_scanner.c"
7663+
#line 7664 "Zend/zend_language_scanner.c"
76597664
yy816:
76607665
YYDEBUG(816, *YYCURSOR);
76617666
++YYCURSOR;
@@ -7696,7 +7701,7 @@ int start_line = CG(zend_lineno);
76967701
zend_copy_value(zendlval, (yytext+1), (yyleng-1));
76977702
RETURN_TOKEN(T_VARIABLE);
76987703
}
7699-
#line 7700 "Zend/zend_language_scanner.c"
7704+
#line 7705 "Zend/zend_language_scanner.c"
77007705
yy821:
77017706
YYDEBUG(821, *YYCURSOR);
77027707
++YYCURSOR;
@@ -7741,7 +7746,7 @@ int start_line = CG(zend_lineno);
77417746
ZVAL_STRINGL(zendlval, yytext, yyleng);
77427747
RETURN_TOKEN(T_NUM_STRING);
77437748
}
7744-
#line 7745 "Zend/zend_language_scanner.c"
7749+
#line 7750 "Zend/zend_language_scanner.c"
77457750
yy829:
77467751
YYDEBUG(829, *YYCURSOR);
77477752
++YYCURSOR;
@@ -7764,6 +7769,6 @@ int start_line = CG(zend_lineno);
77647769
goto yy828;
77657770
}
77667771
}
7767-
#line 2552 "Zend/zend_language_scanner.l"
7772+
#line 2557 "Zend/zend_language_scanner.l"
77687773

77697774
}

Zend/zend_language_scanner.l

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,12 +2486,17 @@ heredoc_scan_done:
24862486
case '\n':
24872487
indentation = spacing = 0;
24882488
2489-
while (*YYCURSOR == ' ' || *YYCURSOR == '\t') {
2489+
while (YYCURSOR < YYLIMIT && (*YYCURSOR == ' ' || *YYCURSOR == '\t')) {
24902490
spacing |= 1 << (*YYCURSOR == '\t');
24912491
++YYCURSOR;
24922492
++indentation;
24932493
}
24942494
2495+
if (YYCURSOR == YYLIMIT) {
2496+
CG(increment_lineno) = 1;
2497+
RETURN_TOKEN(T_ENCAPSED_AND_WHITESPACE);
2498+
}
2499+
24952500
/* Check for ending label on the next line */
24962501
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
24972502
YYCTYPE *end = YYCURSOR + heredoc_label->length;

0 commit comments

Comments
 (0)