git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-web--browse: invoke kfmclient directly

From
Chris Packham <judge.packham@gmail.com>
Date
Sep 18, 2011, 10:20 UTC
Message-ID
<1316341224-4359-1-git-send-email-judge.packham@gmail.com>
In-Reply-To
<20110918032933.GA17977@sigill.intra.peff.net>

Instead of using eval which causes problems when a URL contains an appropriately escaped ampersand (\&).

Cc: peff@peff.net
Cc: chriscool@tuxfamily.org
Cc: jepler@unpythonic.net
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
Show 7 quoted lines
> Which implies that "$browser_path" must be the actual
> executable. In which case, I would think that:
>
>   "$browser_path" "$@" &
>
> would be the right thing. And indeed, that is what the firefox arm of
> the case statement does. But chrome, konqueror, and others use eval.
So here is my attempt at a fix for kfmclient.

For what it's worth I've included a testcase that detects my problem. I'm not sure if the testcase is really worth it because the test library suppresses X applications and even if it didn't the testcase is fairly trivial and might just annoy people by opening web-browsers (and it snaps up the last t99xx prefix).

 git-web--browse.sh         |    4 ++--
 t/t9901-git-web--browse.sh |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100755 t/t9901-git-web--browse.sh
diff --git a/git-web--browse.sh b/git-web--browse.sh
index e9de241..1164a22 100755
--- a/git-web--browse.sh
+++ b/git-web--browse.sh
@@ -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" "$@" &
diff --git a/t/t9901-git-web--browse.sh b/t/t9901-git-web--browse.sh
new file mode 100755
index 0000000..7ed38a0
--- /dev/null
+++ b/t/t9901-git-web--browse.sh
@@ -0,0 +1,43 @@
+#!/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 with
+the supported browsers that are installed on the host system.'
+
+. ./test-lib.sh
+
+test -x /usr/bin/firefox && test_set_prereq FIREFOX
+test -x /usr/bin/konqueror && test_set_prereq KONQUEROR
+test -x /usr/bin/google-chrome && test_set_prereq CHROME
+test -x /usr/bin/opera && test_set_prereq OPERA
+
+test_expect_success \
+	'accepts a URL with an ampersand in it (default)' '
+    git web--browse http://example.com/foo\&bar/
+'
+
+test_expect_success FIREFOX \
+	'accepts a URL with an ampersand in it (firefox)' '
+    git web--browse --browser=firefox http://example.com/foo\&bar/
+'
+
+test_expect_success KONQUEROR \
+	'accepts a URL with an ampersand in it (konqueror)' '
+    git web--browse --browser=konqueror http://example.com/foo\&bar/
+'
+
+test_expect_success OPERA \
+	'accepts a URL with an ampersand in it (opera)' '
+    git web--browse --browser=opera http://example.com/foo\&bar/
+'
+
+test_expect_success CHROME \
+	'accepts a URL with an ampersand in it (chrome)' '
+    git web--browse --browser=google-chrome http://example.com/foo\&bar/
+'
+
+test_done
-- 
1.7.7.rc1.3.g5593.dirty
Previous: Jeff KingNext: Jeff King
Message 9 of 33 in “Configurable hyperlinking in gitk”
  1. Configurable hyperlinking in gitkJeff Epler, Sep 17, 2011
  2. Chris PackhamSep 17, 2011
  3. Chris PackhamSep 17, 2011
  4. Jeff EplerSep 17, 2011
  5. Chris PackhamSep 17, 2011
  6. git web--browse error handling URL with & in it (Was Re: [RFC/PATCH] Configurable hyperlinking in gitk)Chris Packham, Sep 18, 2011
  7. Chris PackhamSep 18, 2011
  8. Jeff KingSep 18, 2011
  9. git-web--browse: invoke kfmclient directlyChris Packham, Sep 18, 2011
  10. Jeff KingSep 18, 2011
  11. [RFC/PATCHv2] git-web--browse: avoid the use of evalChris Packham, Sep 19, 2011
  12. Jeff KingSep 19, 2011
  13. Chris PackhamSep 20, 2011
  14. Jeff KingSep 20, 2011
  15. Junio C HamanoSep 20, 2011
  16. Junio C HamanoSep 19, 2011
  17. Jeff KingSep 19, 2011
  18. Junio C HamanoSep 19, 2011
  19. Jeff KingSep 19, 2011
  20. Junio C HamanoSep 19, 2011
  21. Andreas SchwabSep 19, 2011
  22. Jeff KingSep 19, 2011
  23. Junio C HamanoSep 19, 2011
  24. Andreas SchwabSep 19, 2011
  25. Jakub NarebskiSep 19, 2011
  26. Christian CouderSep 18, 2011
  27. Marc BranchaudSep 19, 2011
  28. Jakub NarebskiSep 18, 2011
  29. Jeff EplerSep 22, 2011
  30. Configurable hyperlinking in gitkJeff Epler, Sep 22, 2011
  31. Configurable hyperlinking in gitkJeff Epler, Oct 11, 2011
  32. Junio C HamanoOct 11, 2011
  33. Chris PackhamOct 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.