Skip to content

Commit d938711

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06fc5c9 commit d938711

7 files changed

+37
-3
lines changed

t/chainlint.sed

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ s/.*\n//
157157
/^[^']*'[^']*$/{
158158
/"[^'"]*'[^'"]*"/!bsqstring
159159
}
160+
:folded
160161
# here-doc -- swallow it
161162
/<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
162163
# comment or empty line -- discard since final non-comment, non-empty line
@@ -255,15 +256,15 @@ s/"//g
255256
N
256257
s/\n//
257258
/"/!bdqstring
258-
bcheckchain
259+
bfolded
259260

260261
# found multi-line single-quoted string '...\n...' -- slurp until end of string
261262
:sqstring
262263
s/'//g
263264
N
264265
s/\n//
265266
/'/!bsqstring
266-
bcheckchain
267+
bfolded
267268

268269
# found here-doc -- swallow it to avoid false hits within its body (but keep
269270
# the command to which it was attached)
@@ -278,7 +279,7 @@ N
278279
}
279280
s/^<[^>]*>//
280281
s/\n.*$//
281-
bcheckchain
282+
bfolded
282283

283284
# found "case ... in" -- pass through untouched
284285
:case
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(
2+
> cat)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(
2+
# LINT: line contains here-doc and closes nested subshell
3+
cat <<-\INPUT)
4+
fizz
5+
INPUT
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(
2+
x=$(bobble &&
3+
?!AMP?!>> wiffle)
4+
echo $x
5+
>)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(
2+
?!AMP?! cat && echo multi-line string"
3+
bap
4+
>)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)

0 commit comments

Comments
 (0)