Skip to content

Commit 7b9e547

Browse files
sunshinecogitster
authored andcommitted
check-non-portable-shell: improve VAR=val shell-func detection
The behavior of a one-shot environment variable assignment of the form "VAR=val cmd" is unspecified according to POSIX when "cmd" is a shell function. Indeed the behavior differs between shell implementations and even different versions of the same shell, thus should be avoided. As such, check-non-portable-shell.pl warns when it detects such usage. However, a limitation of the check is that it only detects such invocations when variable assignment (i.e. `VAR=val`) is the first thing on the line. Thus, it can easily be fooled by an invocation such as: echo X | VAR=val shell-func Address this shortcoming by loosening the check so that the variable assignment can be recognized even when not at the beginning of the line. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bd0cd0 commit 7b9e547

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/check-non-portable-shell.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ sub err {
4949
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
5050
/\blocal\s+[A-Za-z0-9_]*=\$([A-Za-z0-9_{]|[(][^(])/ and
5151
err q(quote "$val" in 'local var=$val');
52-
/^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
52+
/\b([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and !/test_env.+=/ and exists($func{$4}) and
5353
err '"FOO=bar shell_func" is not portable (use test_env FOO=bar shell_func)';
5454
$line = '';
5555
# this resets our $. for each file

0 commit comments

Comments
 (0)