threads / patch / 25462

patcht0003: properly quote $HOME

Subject: [PATCH] t0003: properly quote $HOME

## tl;dr

8 messages between Oct 17, 2010 and Oct 18, 2010. Diffs are folded; open one to read it.

replies: 7people: 5as markdown or json

Thomas Rast· Oct 17, 2010, 19:13 UTC · lore

6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot to quote one instance of $HOME in the tests. This broke the test for me with the shell complaining about an ambiguous redirect (but only when run with --root for some reason).

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 t/t0003-attributes.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to t/t0003-attributes.sh +1 −1
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 25205ac..e75153b 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -38,7 +38,7 @@ test_expect_success 'setup' '
 	) >a/b/.gitattributes
 	(
 		echo "global test=global"
-	) >$HOME/global-gitattributes
+	) >"$HOME"/global-gitattributes
 
 '
 
-- 
1.7.3.1.266.g3c065
Jonathan Nieder· Oct 17, 2010, 19:18 UTC · re: Thomas Rast · lore

Re: [PATCH] t0003: properly quote $HOME

Thomas Rast wrote:
> 6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot
> to quote one instance of $HOME in the tests.  This broke the test for
> me with the shell complaining about an ambiguous redirect (but only
> when run with --root for some reason).
Thanks.  What shell do you use?

IIRC it is not ambiguous according to POSIX but since e.g. OpenBSD complains it is worth fixing.

Thomas Rast· Oct 17, 2010, 19:34 UTC · re: Jonathan Nieder · lore

Re: [PATCH] t0003: properly quote $HOME

Jonathan Nieder wrote:
Show 11 quoted lines
> Thomas Rast wrote:
> 
> > 6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot
> > to quote one instance of $HOME in the tests.  This broke the test for
> > me with the shell complaining about an ambiguous redirect (but only
> > when run with --root for some reason).
> 
> Thanks.  What shell do you use?
> 
> IIRC it is not ambiguous according to POSIX but since e.g. OpenBSD
> complains it is worth fixing.
Oh, huh, so much for the theory that it's --root causing it:
  $ sh ./t0003-attributes.sh -q
  # passed all 8 test(s)
  1..8
  $ dash ./t0003-attributes.sh -q
  # passed all 8 test(s)
  1..8
  $ bash ./t0003-attributes.sh -q
  not ok - 1 setup
[...]
  $ bash --version
  GNU bash, version 4.1.7(1)-release (x86_64-suse-linux-gnu)
[...]
Then again, so much for your theory that it's only OpenBSD... ;-)
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Thomas Rast· Oct 18, 2010, 09:09 UTC · re: Thomas Rast · lore

[PATCH v2] t0003: properly quote $HOME

6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot to quote one instance of $HOME in the tests. This would be valid according to POSIX, but bash 4 helpfully declines to execute the command in question with an "ambiguous redirection" error.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Changed the commit message to state the actual reason.
 t/t0003-attributes.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to t/t0003-attributes.sh +1 −1
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 25205ac..e75153b 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -38,7 +38,7 @@ test_expect_success 'setup' '
 	) >a/b/.gitattributes
 	(
 		echo "global test=global"
-	) >$HOME/global-gitattributes
+	) >"$HOME"/global-gitattributes
 
 '
 
-- 
1.7.3.1.270.gbc760
Jonathan Nieder· Oct 18, 2010, 10:02 UTC · re: Thomas Rast · lore

Re: [PATCH v2] t0003: properly quote $HOME

Thomas Rast wrote:
>                                               This would be valid
> according to POSIX, but bash 4 helpfully declines to execute the
> command in question with an "ambiguous redirection" error.

For the benefit of those wondering why they never saw this problem, even after using bash for a while: bash in POSIX mode (e.g. when running as "sh") does not have the same problem.

Presumably that's why this problem was not noticed until on a platform without bash as /bin/sh, in v1.7.0-rc1~30 (work around an obnoxious bash "safety feature" on OpenBSD, 2010-01-26).

I still like the patch. :)
Matthieu Moy· Oct 17, 2010, 19:37 UTC · re: Thomas Rast · lore

Re: [PATCH] t0003: properly quote $HOME

Thomas Rast <trast@student.ethz.ch> writes:
> 6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot
> to quote one instance of $HOME in the tests.  This broke the test for
> me with the shell complaining about an ambiguous redirect (but only
> when run with --root for some reason).
My bad, sorry. ACK for the fix.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Johannes Sixt· Oct 17, 2010, 21:03 UTC · re: Thomas Rast · lore

Re: [PATCH] t0003: properly quote $HOME

On Sonntag, 17. Oktober 2010, Thomas Rast wrote:
Show 22 quoted lines
> 6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot
> to quote one instance of $HOME in the tests.  This broke the test for
> me with the shell complaining about an ambiguous redirect (but only
> when run with --root for some reason).
>
> Signed-off-by: Thomas Rast <trast@student.ethz.ch>
> ---
>  t/t0003-attributes.sh |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
> index 25205ac..e75153b 100755
> --- a/t/t0003-attributes.sh
> +++ b/t/t0003-attributes.sh
> @@ -38,7 +38,7 @@ test_expect_success 'setup' '
>  	) >a/b/.gitattributes
>  	(
>  		echo "global test=global"
> -	) >$HOME/global-gitattributes
> +	) >"$HOME"/global-gitattributes
>
>  '

FWIW, the failure is due to bash trying to be helpful. Variable expansions after redirections are not word-split, but bash incorrectly detects an "ambiguous redirect" if the expanded text contains IFS characters. Your fix is of course the right way to work it around. But you might update the commit message.

-- Hannes
Junio C Hamano· Oct 18, 2010, 19:15 UTC · re: Thomas Rast · lore

Re: [PATCH] t0003: properly quote $HOME

Thomas Rast <trast@student.ethz.ch> writes:
> 6df42ab (Add global and system-wide gitattributes, 2010-09-01) forgot
> to quote one instance of $HOME in the tests.  This broke the test for
> me with the shell complaining about an ambiguous redirect (but only
> when run with --root for some reason).

Sounds like a similar breakage to what was fixed in 3fa7c3d (work around an obnoxious bash "safety feature" on OpenBSD, 2010-01-26) to me.

Thanks.

← back to recent threads