From d93871143fdb7c11ddea81aa7f698e5eee0246e5 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Aug 2018 04:47:37 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- t/chainlint/here-doc-multi-line-string.expect | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 t/chainlint/here-doc-multi-line-string.expect (limited to 't/chainlint/here-doc-multi-line-string.expect') diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect new file mode 100644 index 0000000000..1e5b724b9d --- /dev/null +++ b/t/chainlint/here-doc-multi-line-string.expect @@ -0,0 +1,4 @@ +( +?!AMP?! cat && echo multi-line string" + bap +>) -- cgit v1.2.3 From 22e3e0241ab5add065411d0d8d493f066764465e Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Aug 2018 04:47:38 -0400 Subject: chainlint: recognize multi-line quoted strings more robustly chainlint.sed recognizes multi-line quoted strings within subshells: echo "abc def" >out && so it can avoid incorrectly classifying lines internal to the string as breaking the &&-chain. To identify the first line of a multi-line string, it checks if the line contains a single quote. However, this is fragile and can be easily fooled by a line containing multiple strings: echo "xyz" "abc def" >out && Make detection more robust by checking for an odd number of quotes rather than only a single one. (Escaped quotes are not handled, but support may be added later.) The original multi-line string recognizer rather cavalierly threw away all but the final quote, whereas the new one is careful to retain all quotes, so the "expected" output of a couple existing chainlint tests is updated to account for this new behavior. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/chainlint/here-doc-multi-line-string.expect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/chainlint/here-doc-multi-line-string.expect') diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect index 1e5b724b9d..32038a070c 100644 --- a/t/chainlint/here-doc-multi-line-string.expect +++ b/t/chainlint/here-doc-multi-line-string.expect @@ -1,4 +1,4 @@ ( -?!AMP?! cat && echo multi-line string" +?!AMP?! cat && echo "multi-line string" bap >) -- cgit v1.2.3