From b64ee6e26fedfd891b34d18eb84187da50163767 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 16 Dec 2014 15:06:12 +0000 Subject: URIEncode search engine queries. --- background_scripts/completion.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index dc5519d5..9d5f8780 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, encodeURIComponent queryTerms[1..].join(" ")) suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy) suggestions.push(suggestion) onComplete(suggestions) -- cgit v1.2.3 From 652a301f70d43a1dc6ce44ae80c53af36e851945 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Dec 2014 16:30:11 +0000 Subject: Use + as separator for search engines. --- background_scripts/completion.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 9d5f8780..3b38faf8 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, encodeURIComponent queryTerms[1..].join(" ")) + searchEngineMatch = searchEngineMatch.replace(/%s/g, queryTerms[1..].join("+")) suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy) suggestions.push(suggestion) onComplete(suggestions) -- cgit v1.2.3 From b226510676e7229ae97d76187ffafda4979d8fe6 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Dec 2014 17:03:38 +0000 Subject: Consistent treatment of search terms. --- background_scripts/completion.coffee | 2 +- lib/utils.coffee | 8 +++++++- 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. -- cgit v1.2.3 From da28e31c467ee2283a2e56baad764e73a8fc8b19 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Dec 2014 17:05:49 +0000 Subject: Consistent treatment of search terms; fix tests. --- tests/unit_tests/utils_test.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee index 556f5b7a..88e9a15b 100644 --- a/tests/unit_tests/utils_test.coffee +++ b/tests/unit_tests/utils_test.coffee @@ -45,7 +45,8 @@ context "convertToUrl", should "convert non-URL terms into search queries", -> assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google") - assert.equal "http://www.google.com/search?q=go%20ogle.com", Utils.convertToUrl("go ogle.com") + assert.equal "http://www.google.com/search?q=go+ogle.com", Utils.convertToUrl("go ogle.com") + assert.equal "http://www.google.com/search?q=%40twitter", Utils.convertToUrl("@twitter") context "hasChromePrefix", should "detect chrome prefixes of URLs", -> -- cgit v1.2.3 From 5c750bb10104aeef8fff6131e24b2889619c3ab7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Dec 2014 17:26:44 +0000 Subject: Consistent treatment of search terms; update comment.. --- lib/utils.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils.coffee b/lib/utils.coffee index f31370f8..1bedb3d1 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -96,8 +96,8 @@ Utils = # 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 + # It would be better to pull the default search engine from chrome itself. However, unfortunately chrome + # does not provide an API for doing so. 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 -- cgit v1.2.3