Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace URI.encode/decode with URI::Parser.escape/unescape #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib_rellinks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def relativize(href, path, absolute_base, root_dir)
# path = actual current location / file path of current page
# absolute_base = the base url for the site

href_url = URI.join(URI.encode(absolute_base), URI.encode(href))
path_url = URI.join(absolute_base, URI.encode(path))
href_url = URI.join(URI::Parser.new.escape(absolute_base), URI::Parser.new.escape(href))
path_url = URI.join(absolute_base, URI::Parser.new.escape(path))
relative_url = path_url.route_to(href_url).to_s
url_out = test_index(relative_url, href_url, absolute_base, root_dir)
if href.match(/^#/)
Expand All @@ -21,7 +21,7 @@ def relativize(href, path, absolute_base, root_dir)
end

def path_is_dir(href_url, absolute_base, root_dir)
decode_href = URI.decode(href_url.to_s.gsub(/%25/, "%"))
decode_href = URI::Parser.new.unescape(href_url.to_s.gsub(/%25/, "%"))
local_target = decode_href.gsub(absolute_base, root_dir + "/")
File.directory?(local_target)
end
Expand All @@ -31,7 +31,7 @@ def test_index(relative_url, href_url, absolute_base, root_dir)
relative_url = rewrite_index(relative_url)
else
fixed_url = relative_url.to_s.gsub(/^\//,"")
test_url = URI.join(URI.encode(absolute_base), URI.encode(fixed_url))
test_url = URI.join(URI::Parser.new.escape(absolute_base), URI::Parser.new.escape(fixed_url))
if path_is_dir(test_url, absolute_base, root_dir)
relative_url = rewrite_index(relative_url)
end
Expand All @@ -56,7 +56,7 @@ def convert_html(html, source_file, root_dir, absolute_base)
elsif h.match(absolute_base) || !h.match(/https*:\/\//)
href = href.gsub(/^\/\//, "/")
raw_out = pre + '="' + relativize(href, path, absolute_base, root_path) + '"'
URI.decode(raw_out)
URI::Parser.new.unescape(raw_out)
else
h
end
Expand Down