Skip to content

Commit 22597af

Browse files
sunshinecogitster
authored andcommitted
chainlint.sed: don't mistake << word in string as here-doc operator
Tighten here-doc recognition to prevent it from being fooled by text which looks like a here-doc operator but happens merely to be the content of a string, such as this real-world case from t7201: echo "<<<<<<< ours" && echo ourside && echo "=======" && echo theirside && echo ">>>>>>> theirs" This problem went unnoticed because chainlint.sed is not a real parser, but rather applies heuristics to pretend to understand shell code. In this case, it saw what it thought was a here-doc operator (`<< ours`), and fell off the end of the test looking for the closing tag "ours" which it never found, thus swallowed the remainder of the test without checking it for &&-chain breakage. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d53614 commit 22597af

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

t/chainlint.sed

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
# here-doc -- swallow it to avoid false hits within its body (but keep the
9090
# command to which it was attached)
9191
/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ {
92+
/"[^"]*<<[^"]*"/bnotdoc
9293
s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
9394
s/[ ]*<<//
9495
:hered
@@ -100,6 +101,7 @@
100101
s/^<[^>]*>//
101102
s/\n.*$//
102103
}
104+
:notdoc
103105

104106
# one-liner "(...) &&"
105107
/^[ ]*!*[ ]*(..*)[ ]*&&[ ]*$/boneline
@@ -151,8 +153,10 @@ s/.*\n//
151153
/"[^'"]*'[^'"]*"/!bsqstr
152154
}
153155
:folded
154-
# here-doc -- swallow it
155-
/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/bheredoc
156+
# here-doc -- swallow it (but not "<<" in a string)
157+
/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/{
158+
/"[^"]*<<[^"]*"/!bheredoc
159+
}
156160
# comment or empty line -- discard since final non-comment, non-empty line
157161
# before closing ")", "done", "elsif", "else", or "fi" will need to be
158162
# re-visited to drop "suspect" marking since final line of those constructs

t/chainlint/not-heredoc.expect

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
echo "<<<<<<< ours" &&
2+
echo ourside &&
3+
echo "=======" &&
4+
echo theirside &&
5+
echo ">>>>>>> theirs" &&
6+
7+
(
8+
echo "<<<<<<< ours" &&
9+
echo ourside &&
10+
echo "=======" &&
11+
echo theirside &&
12+
echo ">>>>>>> theirs" ?!AMP?!
13+
poodle
14+
) >merged

t/chainlint/not-heredoc.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# LINT: "<< ours" inside string is not here-doc
2+
echo "<<<<<<< ours" &&
3+
echo ourside &&
4+
echo "=======" &&
5+
echo theirside &&
6+
echo ">>>>>>> theirs" &&
7+
8+
(
9+
# LINT: "<< ours" inside string is not here-doc
10+
echo "<<<<<<< ours" &&
11+
echo ourside &&
12+
echo "=======" &&
13+
echo theirside &&
14+
echo ">>>>>>> theirs"
15+
poodle
16+
) >merged

0 commit comments

Comments
 (0)