chainlint.sed: make here-doc "<<-" operator recognition more POSIX-like

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>

Eric Sunshine committed Dec 13, 2021 at 01:30 UTC 2d53614210919c2a4eac4a03e9d34da7b9e7ff31
1 file changed +4 -4
t/chainlint.sed
+4 -4
@@ -88,8 +88,8 @@
88
89 # here-doc -- swallow it to avoid false hits within its body (but keep the
90 # command to which it was attached)
91 -/<<[ ]*[-\\'"]*[A-Za-z0-9_]/ {
92 - s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
91 +/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ {
92 + s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
93 s/[ ]*<<//
94 :hered
95 N
@@ -152,7 +152,7 @@ s/.*\n//
152 }
153 :folded
154 # here-doc -- swallow it
155 -/<<[ ]*[-\\'"]*[A-Za-z0-9_]/bheredoc
155 +/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/bheredoc
156 # comment or empty line -- discard since final non-comment, non-empty line
157 # before closing ")", "done", "elsif", "else", or "fi" will need to be
158 # re-visited to drop "suspect" marking since final line of those constructs
@@ -274,7 +274,7 @@ bfolded
274 # found here-doc -- swallow it to avoid false hits within its body (but keep
275 # the command to which it was attached)
276 :heredoc
277 -s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
277 +s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
278 s/[ ]*<<//
279 :hdocsub
280 N