Skip to content

Commit

Permalink
added double slash encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartmckee committed Aug 4, 2010
1 parent bcca1b2 commit 2d027b4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/absolutize.rb
Expand Up @@ -10,19 +10,20 @@ def initialize(base_url, options = {})

@options[:remove_anchors] = false
@options[:force_escaping] = true

@options[:output_debug] = false
end

def url(new_url)
# encode the url if the new url contains spaces but doesn't contain %, i.e isn't already encoded
new_url = new_url.split("#").first if new_url.include?"#" and @options[:remove_anchors]
new_url = new_url.gsub("//", "/") if @options[:force_escaping]
new_url = URI.encode(new_url, " <>\{\}|\\\^\[\]`") if not new_url =~ /%/ and @options[:force_escaping]
begin
URI.join(@base_url, new_url).to_s
rescue URI::InvalidURIError => urie
puts "Unable to use URI.join attempting manually"
puts "Unable to use URI.join attempting manually" if @options[:output_debug]
if @base_url =~ /\Ahttp/ and new_url =~ /\A\//
puts "base url starts with htt and new_url is relative to root"
puts "base url starts with htt and new_url is relative to root" if @options[:output_debug]
uri = URI.parse(@base_url)
if uri.port
"#{uri.scheme}://#{uri.host}:#{uri.port}#{new_url}"
Expand All @@ -35,8 +36,6 @@ def url(new_url)
else
raise "Unable to absolutize #{base_url} and #{new_url}"
end
end

### remove double slashes
end
end
end

0 comments on commit 2d027b4

Please sign in to comment.