Replace File.basename in URL#relative_path_to because it doesn't handle special characters in URLs well

This commit is contained in:
nucular 2016-05-16 03:02:40 +02:00 committed by Thibaut Courouble
parent ceccfc0951
commit 034ecfae72
2 changed files with 9 additions and 1 deletions

View file

@ -100,7 +100,7 @@ module Docs
result << '/' if result != '.'
end
else
dest_dir.parent.relative_path_from(base_dir).join(::File.basename(dest)).to_s
dest_dir.parent.relative_path_from(base_dir).join(dest.split('/').last).to_s
end
end

View file

@ -394,6 +394,14 @@ class DocsUrlTest < MiniTest::Spec
assert_equal 'file', url.relative_path_to('http://example.com/file?query#frag')
end
it "returns 'some:file' with 'http://example.com/some:file'" do
assert_equal 'some:file', url.relative_path_to('http://example.com/some:file')
end
it "returns 'some:file' with 'http://example.com/some:file?query#frag'" do
assert_equal 'some:file', url.relative_path_to('http://example.com/some:file?query#frag')
end
it "returns nil with '/file'" do
assert_nil url.relative_path_to('/file')
end