diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-04-05 17:09:02 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-04-05 22:50:11 -0700 |
commit | 8bfe4861913843b6aac8656aabfd43ac405362e8 (patch) | |
tree | 08b8374f4bc0dbe11aa97e2d5348396387dca3d8 | |
parent | e97f4a6d94103c43a08c864c6ab63e6086812998 (diff) | |
download | git-8bfe4861913843b6aac8656aabfd43ac405362e8.tar.gz |
t: teach lint that RHS of 'local VAR=VAL' needs to be quoted
Teach t/check-non-portable-shell.pl that right hand side of the
assignment done with "local VAR=VAL" need to be quoted. We
deliberately target only VAL that begins with $ so that we can catch
- $variable_reference and positional parameter reference like $4
- $(command substitution)
- ${variable_reference-with_magic}
while excluding
- $'\n' that is a bash-ism freely usable in t990[23]
- $(( arithmetic )) whose result should be $IFS safe.
- $? that also is $IFS safe
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | t/check-non-portable-shell.pl | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index dd8107cd7d..b2b28c2ced 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -47,6 +47,8 @@ while (<>) { /\bgrep\b.*--file\b/ and err 'grep --file FILE is not portable (use grep -f FILE)'; /\b[ef]grep\b/ and err 'egrep/fgrep obsolescent (use grep -E/-F)'; /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)'; + /\blocal\s+[A-Za-z0-9_]*=\$([A-Za-z0-9_{]|[(][^(])/ and + err q(quote "$val" in 'local var=$val'); /^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and err '"FOO=bar shell_func" assignment extends beyond "shell_func"'; $line = ''; |