aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2014-12-28 17:03:38 +0000
committerStephen Blott2014-12-28 17:03:38 +0000
commitb226510676e7229ae97d76187ffafda4979d8fe6 (patch)
tree16083d0678e477060484b0ba763ddf2eb52d8cea
parent652a301f70d43a1dc6ce44ae80c53af36e851945 (diff)
downloadvimium-b226510676e7229ae97d76187ffafda4979d8fe6.tar.bz2
Consistent treatment of search terms.
-rw-r--r--background_scripts/completion.coffee2
-rw-r--r--lib/utils.coffee8
2 files changed, 8 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 3b38faf8..d62f82fe 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -327,7 +327,7 @@ class SearchEngineCompleter
searchEngineMatch = this.getSearchEngineMatches(queryTerms[0])
suggestions = []
if searchEngineMatch
- searchEngineMatch = searchEngineMatch.replace(/%s/g, queryTerms[1..].join("+"))
+ searchEngineMatch = searchEngineMatch.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])
suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
suggestions.push(suggestion)
onComplete(suggestions)
diff --git a/lib/utils.coffee b/lib/utils.coffee
index b7f8731a..f31370f8 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -88,11 +88,17 @@ Utils =
# Fallback: no URL
return false
+ # Map a search query to its URL encoded form. The query may be either a string or an array of strings.
+ # E.g. "BBC Sport" -> "BBC+Sport".
+ createSearchQuery: (query) ->
+ query = query.split(/\s+/) if typeof(query) == "string"
+ query.map(encodeURIComponent).join "+"
+
# Creates a search URL from the given :query.
createSearchUrl: (query) ->
# it would be better to pull the default search engine from chrome itself,
# but it is not clear if/how that is possible
- Settings.get("searchUrl") + encodeURIComponent(query)
+ Settings.get("searchUrl") + @createSearchQuery query
# Converts :string into a Google search if it's not already a URL. We don't bother with escaping characters
# as Chrome will do that for us.