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>
/^[^']*'[^']*$/{
/"[^'"]*'[^'"]*"/!bsqstring
}
+:folded
# here-doc -- swallow it
/<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
# comment or empty line -- discard since final non-comment, non-empty line
N
s/\n//
/"/!bdqstring
-bcheckchain
+bfolded
# found multi-line single-quoted string '...\n...' -- slurp until end of string
:sqstring
N
s/\n//
/'/!bsqstring
-bcheckchain
+bfolded
# found here-doc -- swallow it to avoid false hits within its body (but keep
# the command to which it was attached)
}
s/^<[^>]*>//
s/\n.*$//
-bcheckchain
+bfolded
# found "case ... in" -- pass through untouched
:case
--- /dev/null
+(
+# LINT: line contains here-doc and closes nested subshell
+ cat <<-\INPUT)
+ fizz
+ INPUT
--- /dev/null
+(
+ x=$(bobble &&
+?!AMP?!>> wiffle)
+ echo $x
+>)
--- /dev/null
+(
+# LINT: line contains here-doc and opens multi-line $(...)
+ x=$(bobble <<-\END &&
+ fossil
+ vegetable
+ END
+ wiffle)
+ echo $x
+)
--- /dev/null
+(
+?!AMP?! cat && echo multi-line string"
+ bap
+>)
--- /dev/null
+(
+# LINT: line contains here-doc and opens multi-line string
+ cat <<-\TXT && echo "multi-line
+ string"
+ fizzle
+ TXT
+ bap
+)