Skip to content

Commit 6427caf

Browse files
committed
Perl: reject "<< HEREDOC" as a heredoc
If there is a whitespace between the starter (<<) and the marker "HEREDOC", is must be a shift operator. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent f9565bd commit 6427caf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

parsers/perl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ static const unsigned char *collectHereDocMarker (struct hereDocMarkerManager *m
526526
unsigned char *cp = NULL;
527527
bool indented = false;
528528
unsigned char quote_char = 0;
529+
bool space_seen = false;
529530

530531
if (starter == NULL)
531532
return NULL;
@@ -536,7 +537,12 @@ static const unsigned char *collectHereDocMarker (struct hereDocMarkerManager *m
536537

537538
cp = starter + 2;
538539
while (isspace (*cp))
540+
{
541+
/* To avoid confusing with a shift operator, we track
542+
* spaces after the starter (<<). */
543+
space_seen = true;
539544
cp++;
545+
}
540546

541547
if (*cp == '\0')
542548
return NULL;
@@ -547,6 +553,8 @@ static const unsigned char *collectHereDocMarker (struct hereDocMarkerManager *m
547553
return cp + 1;
548554

549555
if (*cp == '~') {
556+
if (space_seen)
557+
return cp + 1;
550558
indented = true;
551559
cp++;
552560
if (*cp == '\0')
@@ -570,6 +578,8 @@ static const unsigned char *collectHereDocMarker (struct hereDocMarkerManager *m
570578
return NULL;
571579
break;
572580
default:
581+
if (space_seen)
582+
return cp;
573583
break;
574584
}
575585

0 commit comments

Comments
 (0)