aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-05-17 14:10:40 +0100
committerStephen Blott2015-05-17 14:10:40 +0100
commit9b0c37c755fd964edf02271f9051f0f6e33e2431 (patch)
tree34c455ae79ee9219e45b5061b29384a050c8b9ca
parent8b966e3d2b313f68f83a2c824ca81f9d80aee059 (diff)
downloadvimium-9b0c37c755fd964edf02271f9051f0f6e33e2431.tar.bz2
use a less brittle approach to decoding URIs.
-rw-r--r--background_scripts/completion.coffee8
-rw-r--r--lib/utils.coffee6
2 files changed, 4 insertions, 10 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 11c63cf0..56740efd 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -131,13 +131,7 @@ class Suggestion
shortenUrl: () ->
return @shortUrl if @shortUrl?
# We get easier-to-read shortened URLs if we URI-decode them.
- url =
- try
- # decodeURI can raise an exception.
- url = decodeURI @url
- catch
- @url
- url = url.toLowerCase()
+ url = (Utils.decodeURIByParts(@url) || @url).toLowerCase()
for [ filter, replacements ] in @stripPatterns
if new RegExp(filter).test url
for replace in replacements
diff --git a/lib/utils.coffee b/lib/utils.coffee
index cbc937b6..9a5661de 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -39,10 +39,10 @@ Utils =
urlPrefix = new RegExp "^[a-z]{3,}://."
(url) -> urlPrefix.test url
- # Decode valid escape sequences in a Javascript URI. This is intended to mimic the best-effort decoding
+ # Decode valid escape sequences in a URI. This is intended to mimic the best-effort decoding
# Chrome itself seems to apply when a Javascript URI is enetered into the omnibox (or clicked).
# See https://code.google.com/p/chromium/issues/detail?id=483000, #1611 and #1636.
- decodeJavascriptURI: (uri) ->
+ decodeURIByParts: (uri) ->
uri.split(/(?=%)/).map((uriComponent) ->
try
decodeURIComponent uriComponent
@@ -123,7 +123,7 @@ Utils =
if Utils.hasChromePrefix string
string
else if Utils.hasJavascriptPrefix string
- Utils.decodeJavascriptURI string
+ Utils.decodeURIByParts string
else if Utils.isUrl string
Utils.createFullUrl string
else