]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chainlint.sed: make here-doc "<<-" operator recognition more POSIX-like
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 13 Dec 2021 06:30:55 +0000 (01:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 22:15:29 +0000 (14:15 -0800)
According to POSIX, "<<" and "<<-" are distinct shell operators. For the
latter to be recognized, no whitespace is allowed before the "-", though
whitespace is allowed after the operator. However, the chainlint
patterns which identify here-docs are both too loose and too tight,
incorrectly allowing whitespace between "<<" and "-" but disallowing it
between "-" and the here-doc tag. Fix the patterns to better match
POSIX.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/chainlint.sed

index 2689e13636f7036a90b0ad9c03d979c428b30588..b38274652604bdeec6804ec4e429a976b55252bf 100644 (file)
@@ -88,8 +88,8 @@
 
 # here-doc -- swallow it to avoid false hits within its body (but keep the
 # command to which it was attached)
-/<<[   ]*[-\\'"]*[A-Za-z0-9_]/ {
-       s/^\(.*\)<<[    ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
+/<<-*[         ]*[\\'"]*[A-Za-z0-9_]/ {
+       s/^\(.*\)<<-*[  ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
        s/[     ]*<<//
        :hered
        N
@@ -152,7 +152,7 @@ s/.*\n//
 }
 :folded
 # here-doc -- swallow it
-/<<[   ]*[-\\'"]*[A-Za-z0-9_]/bheredoc
+/<<-*[         ]*[\\'"]*[A-Za-z0-9_]/bheredoc
 # comment or empty line -- discard since final non-comment, non-empty line
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
@@ -274,7 +274,7 @@ bfolded
 # found here-doc -- swallow it to avoid false hits within its body (but keep
 # the command to which it was attached)
 :heredoc
-s/^\(.*\)<<[   ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
+s/^\(.*\)<<-*[         ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
 s/[    ]*<<//
 :hdocsub
 N