chainlint: let here-doc and multi-line string commence on same line

After swallowing a here-doc, chainlint.sed assumes that no other processing needs to be done on the line aside from checking for &&-chain breakage; likewise, after folding a multi-line quoted string. However, it's conceivable (even if unlikely in practice) that both a here-doc and a multi-line quoted string might commence on the same line: cat <<\EOF && echo "foo bar" data EOF Support this case by sending the line (after swallowing and folding) through the normal processing sequence rather than jumping directly to the check for broken &&-chain. This change also allows other somewhat pathological cases to be handled, such as closing a subshell on the same line starting a here-doc: ( cat <<-\INPUT) data INPUT or, for instance, opening a multi-line $(...) expression on the same line starting a here-doc: x=$(cat <<-\END && data END echo "x") among others. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 13, 2018 at 04:47 UTC d93871143fdb7c11ddea81aa7f698e5eee0246e5
7 files changed +37 -3
t/chainlint.sed
+4 -3
@@ -157,6 +157,7 @@ s/.*\n//
157 /^[^']*'[^']*$/{
158 /"[^'"]*'[^'"]*"/!bsqstring
159 }
160 +:folded
161 # here-doc -- swallow it
162 /<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
163 # comment or empty line -- discard since final non-comment, non-empty line
@@ -255,7 +256,7 @@ s/"//g
256 N
257 s/\n//
258 /"/!bdqstring
258 -bcheckchain
259 +bfolded
260
261 # found multi-line single-quoted string '...\n...' -- slurp until end of string
262 :sqstring
@@ -263,7 +264,7 @@ s/'//g
264 N
265 s/\n//
266 /'/!bsqstring
266 -bcheckchain
267 +bfolded
268
269 # found here-doc -- swallow it to avoid false hits within its body (but keep
270 # the command to which it was attached)
@@ -278,7 +279,7 @@ N
279 }
280 s/^<[^>]*>//
281 s/\n.*$//
281 -bcheckchain
282 +bfolded
283
284 # found "case ... in" -- pass through untouched
285 :case
t/chainlint/here-doc-close-subshell.expect new
+2
@@ -0,0 +1,2 @@
1 +(
2 +> cat)
t/chainlint/here-doc-close-subshell.test new
+5
@@ -0,0 +1,5 @@
1 +(
2 +# LINT: line contains here-doc and closes nested subshell
3 + cat <<-\INPUT)
4 + fizz
5 + INPUT
t/chainlint/here-doc-multi-line-command-subst.expect new
+5
@@ -0,0 +1,5 @@
1 +(
2 + x=$(bobble &&
3 +?!AMP?!>> wiffle)
4 + echo $x
5 +>)
t/chainlint/here-doc-multi-line-command-subst.test new
+9
@@ -0,0 +1,9 @@
1 +(
2 +# LINT: line contains here-doc and opens multi-line $(...)
3 + x=$(bobble <<-\END &&
4 + fossil
5 + vegetable
6 + END
7 + wiffle)
8 + echo $x
9 +)
t/chainlint/here-doc-multi-line-string.expect new
+4
@@ -0,0 +1,4 @@
1 +(
2 +?!AMP?! cat && echo multi-line string"
3 + bap
4 +>)
t/chainlint/here-doc-multi-line-string.test new
+8
@@ -0,0 +1,8 @@
1 +(
2 +# LINT: line contains here-doc and opens multi-line string
3 + cat <<-\TXT && echo "multi-line
4 + string"
5 + fizzle
6 + TXT
7 + bap
8 +)