Skip to content

Commit

Permalink
Teach URL canonicalizer about 'view-source:' prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
int3 committed Jun 21, 2012
1 parent 34f8f2d commit 9976c25
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Utils =

# Completes a partial URL (without scheme)
createFullUrl: (partialUrl) ->
if (!/^[a-z]{3,}:\/\//.test(partialUrl))
partialUrl = "http://" + partialUrl
partialUrl
if (!/^[a-z]{3,}:\/\//.test(partialUrl)) and not /^view-source:/.test partialUrl
"http://" + partialUrl
else
partialUrl

# Tries to detect, whether :str is a valid URL.
isUrl: (str) ->
Expand All @@ -53,6 +54,10 @@ Utils =
# are there more?
specialHostNames = [ 'localhost' ]

# special-case view-source:[url]
if /^view-source:/.test str
return true

# it starts with a scheme, so it's definitely an URL
if (/^[a-z]{3,}:\/\//.test(str))
return true
Expand Down

0 comments on commit 9976c25

Please sign in to comment.