Skip to content

Commit 3042b6b

Browse files
sunshinecogitster
authored andcommitted
chainlint: match "quoted" here-doc tags
A here-doc tag can be quoted ('EOF'/"EOF") or escaped (\EOF) to suppress interpolation within the body. chainlint recognizes single-quoted and escaped tags, but does not know about double-quoted tags. For completeness, teach it to recognize double-quoted tags, as well. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f69176 commit 3042b6b

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

t/chainlint.sed

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494

9595
# here-doc -- swallow it to avoid false hits within its body (but keep the
9696
# command to which it was attached)
97-
/<<[ ]*[-\\']*[A-Za-z0-9_]/ {
98-
s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
97+
/<<[ ]*[-\\'"]*[A-Za-z0-9_]/ {
98+
s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
9999
s/[ ]*<<//
100100
:hereslurp
101101
N
@@ -159,7 +159,7 @@ s/.*\n//
159159
}
160160
:folded
161161
# here-doc -- swallow it
162-
/<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
162+
/<<[ ]*[-\\'"]*[A-Za-z0-9_]/bheredoc
163163
# comment or empty line -- discard since final non-comment, non-empty line
164164
# before closing ")", "done", "elsif", "else", or "fi" will need to be
165165
# re-visited to drop "suspect" marking since final line of those constructs
@@ -281,7 +281,7 @@ bfolded
281281
# found here-doc -- swallow it to avoid false hits within its body (but keep
282282
# the command to which it was attached)
283283
:heredoc
284-
s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
284+
s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
285285
s/[ ]*<<//
286286
:hereslurpsub
287287
N

t/chainlint/here-doc.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ cat >foo &&
44

55
cat >bar &&
66

7+
cat >boo &&
8+
79
horticulture

t/chainlint/here-doc.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ boz
2121
woz
2222
FUMP
2323

24+
# LINT: swallow "quoted" here-doc
25+
cat <<"zump" >boo &&
26+
snoz
27+
boz
28+
woz
29+
zump
30+
2431
# LINT: swallow here-doc (EOF is last line of test)
2532
horticulture <<\EOF
2633
gomez

t/chainlint/subshell-here-doc.expect

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
(
77
cat >bup &&
88
cat >bup2 &&
9+
cat >bup3 &&
910
meep
1011
>)

t/chainlint/subshell-here-doc.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@
3131
glink
3232
FIZZ
3333
ARBITRARY2
34+
cat <<-"ARBITRARY3" >bup3 &&
35+
glink
36+
FIZZ
37+
ARBITRARY3
3438
meep
3539
)

0 commit comments

Comments
 (0)