aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStephen Blott2014-11-08 07:40:49 +0000
committerStephen Blott2014-11-08 07:40:49 +0000
commit3d647c9d062a84082d0337ac0b0004d31eb64969 (patch)
tree9ff193d27f26d931b06018e36662cde2faef2a91 /lib
parent8e4e95c87d2ea06fcc0d9d354a180dfa1f31cdd2 (diff)
parent56565a021ae421d648a3b4180fdd255270245421 (diff)
downloadvimium-3d647c9d062a84082d0337ac0b0004d31eb64969.tar.bz2
Merge branch 'smblott-github-domains-only-domains'
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.coffee19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index bbcee1a0..b7f8731a 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -26,28 +26,29 @@ Utils =
-> id += 1
hasChromePrefix: do ->
- chromePrefixes = [ "about:", "view-source:", "chrome-extension:", "data:" ]
+ chromePrefixes = [ "about:", "view-source:", "extension:", "chrome-extension:", "data:" ]
(url) ->
if 0 < url.indexOf ":"
for prefix in chromePrefixes
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
-
# Must not contain spaces
return false if ' ' in str
+ # Starts with a scheme: URL
+ return true if @hasFullUrlPrefix str
+
# More or less RFC compliant URL host part parsing. This should be sufficient for our needs
urlRegex = new RegExp(
'^(?:([^:]+)(?::([^:]+))?@)?' + # user:password (optional) => \1, \2
@@ -98,7 +99,7 @@ Utils =
convertToUrl: (string) ->
string = string.trim()
- # Special-case about:[url] and view-source:[url]
+ # Special-case about:[url], view-source:[url] and the like
if Utils.hasChromePrefix string
string
else if Utils.isUrl string