aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Perry-Nguyen2018-09-14 13:13:20 -0400
committerRyan Perry-Nguyen2018-09-14 13:13:20 -0400
commit2ee06443f4cfc72445625c2a09238866a82059f5 (patch)
tree7c8d5f840f9e184f652c71e2766d68d91dfd9965
parent880b64b0caeb73b0803034f4a27bde78c66d2eaa (diff)
downloadvimium-2ee06443f4cfc72445625c2a09238866a82059f5.tar.bz2
dont queries for %S replacement
-rw-r--r--lib/utils.coffee3
-rw-r--r--tests/unit_tests/utils_test.coffee3
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 6f38be8f..45a880e5 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -131,7 +131,8 @@ Utils =
# It would be better to pull the default search engine from chrome itself. However, chrome does not provide
# an API for doing so.
createSearchUrl: (query, searchUrl = Settings.get("searchUrl")) ->
- searchUrl += "%s" unless 0 <= searchUrl.indexOf "%s"
+ searchUrl += "%s" if -1 == searchUrl.indexOf("%s") + searchUrl.indexOf("%S")
+ searchUrl = searchUrl.replace /%S/g, query
searchUrl.replace /%s/g, @createSearchQuery query
# Extract a query from url if it appears to be a URL created from the given search URL.
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee
index 2794a6d7..7439ddf7 100644
--- a/tests/unit_tests/utils_test.coffee
+++ b/tests/unit_tests/utils_test.coffee
@@ -57,6 +57,9 @@ context "extractQuery",
assert.equal "bbc sport 3", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+3"
assert.equal "bbc sport 4", Utils.extractQuery "https://www.google.ie/search?q=%s", "http://www.google.ie/search?q=bbc+sport+4&blah"
+ should "replace %S without encoding", ->
+ assert.equal "vimium/pulls", Utils.extractQuery "https://www.github.com/philc/%S", "https://www.github.com/philc/vimium/pulls"
+
should "extract not queries from incorrect search URLs", ->
assert.isFalse Utils.extractQuery "https://www.google.ie/search?q=%s&foo=bar", "https://www.google.ie/search?q=bbc+sport"