From c2c29cc03e0d8156095dd18e2f7dcb768253c61a Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Aug 2018 04:47:34 -0400 Subject: chainlint: match arbitrary here-docs tags rather than hard-coded names chainlint.sed swallows top-level here-docs to avoid being fooled by content which might look like start-of-subshell. It likewise swallows here-docs in subshells to avoid marking content lines as breaking the &&-chain, and to avoid being fooled by content which might look like end-of-subshell, start-of-nested-subshell, or other specially-recognized constructs. At the time of implementation, it was believed that it was not possible to support arbitrary here-doc tag names since 'sed' provides no way to stash the opening tag name in a variable for later comparison against a line signaling end-of-here-doc. Consequently, tag names are hard-coded, with "EOF" being the only tag recognized at the top-level, and only "EOF", "EOT", and "INPUT_END" being recognized within subshells. Also, special care was taken to avoid being confused by here-docs nested within other here-docs. In practice, this limited number of hard-coded tag names has been "good enough" for the 13000+ existing Git test, despite many of those tests using tags other than the recognized ones, since the bodies of those here-docs do not contain content which would fool the linter. Nevertheless, the situation is not ideal since someone writing new tests, and choosing a name not in the "blessed" set could potentially trigger a false-positive. To address this shortcoming, upgrade chainlint.sed to handle arbitrary here-doc tag names, both at the top-level and within subshells. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/chainlint/subshell-here-doc.test | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't/chainlint/subshell-here-doc.test') diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test index 9c3564c247..05139af0b5 100644 --- a/t/chainlint/subshell-here-doc.test +++ b/t/chainlint/subshell-here-doc.test @@ -20,4 +20,12 @@ wednesday pugsly EOF +) && +( +# LINT: swallow here-doc with arbitrary tag + cat <<-\ARBITRARY >bup && + glink + FIZZ + ARBITRARY + meep ) -- cgit v1.2.3 From 7e32a31b2101c3ced65ea9367c747930a4eb39d9 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Aug 2018 04:47:35 -0400 Subject: chainlint: match 'quoted' here-doc tags A here-doc tag can be quoted ('EOF') or escaped (\EOF) to suppress interpolation within the body. Although, chainlint recognizes escaped tags, it does not know about quoted tags. For completeness, teach it to recognize quoted tags, as well. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/chainlint/subshell-here-doc.test | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/chainlint/subshell-here-doc.test') diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test index 05139af0b5..b6b5a9b33a 100644 --- a/t/chainlint/subshell-here-doc.test +++ b/t/chainlint/subshell-here-doc.test @@ -27,5 +27,9 @@ glink FIZZ ARBITRARY + cat <<-'ARBITRARY2' >bup2 && + glink + FIZZ + ARBITRARY2 meep ) -- cgit v1.2.3