aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.coffee
diff options
context:
space:
mode:
authorStephen Blott2014-11-06 08:50:59 +0000
committerStephen Blott2014-11-06 08:50:59 +0000
commit46ee1444e08815cd3ec4d1f008d62d13b35ad777 (patch)
tree0a2cb24a0a036925eea3c4e52eb891cc60a451bf /lib/utils.coffee
parentc08d03e36e3c6a08fe9eaa493fb2a3262f77b74b (diff)
downloadvimium-46ee1444e08815cd3ec4d1f008d62d13b35ad777.tar.bz2
Include scheme for domain suggestions; tighter test for valid domain.
Diffstat (limited to 'lib/utils.coffee')
-rw-r--r--lib/utils.coffee11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index e2ed8d98..62749496 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -33,17 +33,18 @@ Utils =
return true if url.startsWith prefix
false
+ hasFullUrlPrefix: do ->
+ urlPrefix = new RegExp "^[a-z]{3,}://."
+ (url) -> urlPrefix.test url
+
# Completes a partial URL (without scheme)
createFullUrl: (partialUrl) ->
- unless /^[a-z]{3,}:\/\//.test partialUrl
- "http://" + partialUrl
- else
- partialUrl
+ if @hasFullUrlPrefix(partialUrl) then partialUrl else ("http://" + partialUrl)
# Tries to detect if :str is a valid URL.
isUrl: (str) ->
# Starts with a scheme: URL
- return true if /^[a-z]{3,}:\/\//.test str
+ return true if @hasFullUrlPrefix str
# Must not contain spaces
return false if ' ' in str