git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: git@vger.kernel.org
Cc: Chris Packham <judge.packham@gmail.com>,
	peff@peff.net, chriscool@tuxfamily.org, jepler@unpythonic.net
Subject: [RFC/PATCHv2] git-web--browse: avoid the use of eval
Date: Mon, 19 Sep 2011 21:26:55 +1200	[thread overview]
Message-ID: <1316424415-11156-1-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <20110918183846.GA31176@sigill.intra.peff.net>

Using eval causes problems when the URL contains an appropriately
escaped ampersand (\&). Dropping eval from the built-in browser
invocation avoids the problem.

Cc: peff@peff.net
Cc: chriscool@tuxfamily.org
Cc: jepler@unpythonic.net

Signed-off-by: Chris Packham <judge.packham@gmail.com>

---
Here's an updated patch which drops the uses of eval when invoking a
supported browser. The default case still uses eval but adds some extra
quoting which also fixes the problem. I've avoided touching the 'start'
case because I don't have access to a windows system to test with.

I've replaced my tests With the test suggested by Peff (should I be
giving him credit in the copyright line or something?). I've grabbed
t9901 but if there is a better set of miscellaneous minor tests that I
should be using let me know.

 git-web--browse.sh         |   10 +++++-----
 t/t9901-git-web--browse.sh |   21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)
 create mode 100755 t/t9901-git-web--browse.sh

diff --git a/git-web--browse.sh b/git-web--browse.sh
index e9de241..ee05f10 100755
--- a/git-web--browse.sh
+++ b/git-web--browse.sh
@@ -156,7 +156,7 @@ firefox|iceweasel|seamonkey|iceape)
 	;;
 google-chrome|chrome|chromium|chromium-browser)
 	# No need to specify newTab. It's default in chromium
-	eval "$browser_path" "$@" &
+	"$browser_path" "$@" &
 	;;
 konqueror)
 	case "$(basename "$browser_path")" in
@@ -164,10 +164,10 @@ konqueror)
 		# It's simpler to use kfmclient to open a new tab in konqueror.
 		browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
 		type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
-		eval "$browser_path" newTab "$@"
+		"$browser_path" newTab "$@" &
 		;;
 	kfmclient)
-		eval "$browser_path" newTab "$@"
+		"$browser_path" newTab "$@" &
 		;;
 	*)
 		"$browser_path" "$@" &
@@ -175,7 +175,7 @@ konqueror)
 	esac
 	;;
 w3m|elinks|links|lynx|open)
-	eval "$browser_path" "$@"
+	"$browser_path" "$@"
 	;;
 start)
 	exec "$browser_path" '"web-browse"' "$@"
@@ -185,7 +185,7 @@ opera|dillo)
 	;;
 *)
 	if test -n "$browser_cmd"; then
-		( eval $browser_cmd "$@" )
+		( eval $browser_cmd \""$@"\" )
 	fi
 	;;
 esac
diff --git a/t/t9901-git-web--browse.sh b/t/t9901-git-web--browse.sh
new file mode 100755
index 0000000..141ed17
--- /dev/null
+++ b/t/t9901-git-web--browse.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Copyright (c) 2011 Chris Packham
+#
+
+test_description='git web--browse basic tests
+
+This test checks that git web--browse can handle various valid URLs.'
+
+. ./test-lib.sh
+
+test_expect_success \
+	'accepts a URL with an ampersand in it' '
+	echo http://example.com/foo\&bar/ >expect &&
+	git config browser.custom.cmd echo &&
+	git web--browse --browser=custom \
+		http://example.com/foo\&bar/ >actual &&
+	test_cmp expect actual
+'
+
+test_done
-- 
1.7.7.rc1.4.g47f23.dirty

  reply	other threads:[~2011-09-19  9:26 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-17  2:29 [RFC/PATCH] Configurable hyperlinking in gitk Jeff Epler
2011-09-17  9:26 ` Chris Packham
2011-09-17 10:01   ` Chris Packham
2011-09-17 13:45   ` Jeff Epler
2011-09-17 23:33     ` Chris Packham
2011-09-18  0:30       ` git web--browse error handling URL with & in it (Was Re: [RFC/PATCH] Configurable hyperlinking in gitk) Chris Packham
2011-09-18  0:32         ` Chris Packham
2011-09-18  3:29           ` Jeff King
2011-09-18 10:20             ` [PATCH] git-web--browse: invoke kfmclient directly Chris Packham
2011-09-18 18:38               ` Jeff King
2011-09-19  9:26                 ` Chris Packham [this message]
2011-09-19 18:34                   ` [RFC/PATCHv2] git-web--browse: avoid the use of eval Jeff King
2011-09-20  9:04                     ` Chris Packham
2011-09-20 18:49                       ` Jeff King
2011-09-20 19:35                         ` Junio C Hamano
2011-09-19 17:57                 ` [PATCH] git-web--browse: invoke kfmclient directly Junio C Hamano
2011-09-19 18:20                   ` Jeff King
2011-09-19 20:42                     ` Junio C Hamano
2011-09-19 20:44                       ` Jeff King
2011-09-19 21:22                         ` Junio C Hamano
2011-09-19 21:46                           ` Andreas Schwab
2011-09-19 22:23                             ` Jeff King
2011-09-19 22:28                               ` Junio C Hamano
2011-09-19 20:44                     ` Andreas Schwab
2011-09-19 21:32                   ` Jakub Narebski
2011-09-18 14:46             ` git web--browse error handling URL with & in it (Was Re: [RFC/PATCH] Configurable hyperlinking in gitk) Christian Couder
2011-09-19 15:05       ` [RFC/PATCH] Configurable hyperlinking in gitk Marc Branchaud
2011-09-18 18:50   ` Jakub Narebski
2011-09-22  1:31     ` Jeff Epler
2011-09-22  2:15       ` [PATCH v3] " Jeff Epler
2011-10-11 18:37       ` [RESEND PATCH " Jeff Epler
2011-10-11 22:13         ` Junio C Hamano
2011-10-12  9:07           ` Chris Packham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316424415-11156-1-git-send-email-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=jepler@unpythonic.net \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).