From 9d7ad8967ba7af7e8e273655078f6c7690fd1824 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Dec 2020 03:04:28 +0100 Subject: Escape single quotes in URL On Unix, we escape the URL argument by surrounding it with single quotes. This fails if the URL contains single quotes. It also fails if the `BROWSER` command contains `%s` not surrounded by single quotes. Fix this by escaping the single quotes. We might also want to look into passing the `BROWSER` command and arguments into `exec.Command` directly instead of through `/bin/sh` and checking if that has an automatic escaping mechanism we can take advantage of. --- browserenv_unix_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'browserenv_unix_test.go') diff --git a/browserenv_unix_test.go b/browserenv_unix_test.go index f49444e..0d61a52 100644 --- a/browserenv_unix_test.go +++ b/browserenv_unix_test.go @@ -33,6 +33,12 @@ func TestBrowserCommand(t *testing.T) { "https://duckduckgo.com", "open -a Firefox https://duckduckgo.com --other-arg", }, + { + "escapes single quotes in URL", + "open -a Firefox", + "https://duckduckgo.com/?q='s-Hertogenbosch", + "open -a Firefox 'https://duckduckgo.com/?q=%27s-Hertogenbosch'", + }, } for _, test := range tests { -- cgit v1.2.3