aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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"