Skip to content

Commit c53064f

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78441: Parse error due to heredoc identifier followed by digit
2 parents 7d4e3dc + 1eb75f2 commit c53064f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Zend/tests/grammar/bug78441.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #78441 (Parse error due to heredoc identifier followed by digit)
3+
--FILE--
4+
<?php
5+
echo <<<FOO
6+
FOO4
7+
FOO, PHP_EOL;
8+
9+
echo <<<FOO
10+
bar
11+
FOO4
12+
FOO, PHP_EOL;
13+
14+
echo <<<'FOO'
15+
bar
16+
FOO4
17+
FOO, PHP_EOL;
18+
?>
19+
--EXPECT--
20+
FOO4
21+
bar
22+
FOO4
23+
bar
24+
FOO4

Zend/zend_language_scanner.l

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ do { \
113113
#define GET_DOUBLE_QUOTES_SCANNED_LENGTH() SCNG(scanned_string_len)
114114

115115
#define IS_LABEL_START(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || (c) == '_' || (c) >= 0x80)
116+
#define IS_LABEL_SUCCESSOR(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= '0' && (c) <= '9') || (c) == '_' || (c) >= 0x80)
116117

117118
#define ZEND_IS_OCT(c) ((c)>='0' && (c)<='7')
118119
#define ZEND_IS_HEX(c) (((c)>='0' && (c)<='9') || ((c)>='a' && (c)<='f') || ((c)>='A' && (c)<='F'))
@@ -2419,7 +2420,7 @@ skip_escape_conversion:
24192420
24202421
/* Check for ending label on the next line */
24212422
if (heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, s, heredoc_label->length)) {
2422-
if (!IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2423+
if (!IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
24232424
if (spacing == (HEREDOC_USING_SPACES | HEREDOC_USING_TABS)) {
24242425
zend_throw_exception(zend_ce_parse_error, "Invalid indentation - tabs and spaces cannot be mixed", 0);
24252426
}
@@ -2676,7 +2677,7 @@ double_quotes_scan_done:
26762677
26772678
/* Check for ending label on the next line */
26782679
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
2679-
if (IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2680+
if (IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
26802681
continue;
26812682
}
26822683
@@ -2797,7 +2798,7 @@ heredoc_scan_done:
27972798
27982799
/* Check for ending label on the next line */
27992800
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
2800-
if (IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2801+
if (IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
28012802
continue;
28022803
}
28032804

0 commit comments

Comments
 (0)