Skip to content

Commit 034ecfa

Browse files
nucularThibaut
authored andcommitted
Replace File.basename in URL#relative_path_to because it doesn't handle special characters in URLs well
1 parent ceccfc0 commit 034ecfa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/docs/core/url.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def relative_path_to(url)
100100
result << '/' if result != '.'
101101
end
102102
else
103-
dest_dir.parent.relative_path_from(base_dir).join(::File.basename(dest)).to_s
103+
dest_dir.parent.relative_path_from(base_dir).join(dest.split('/').last).to_s
104104
end
105105
end
106106

test/lib/docs/core/url_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ class DocsUrlTest < MiniTest::Spec
394394
assert_equal 'file', url.relative_path_to('http://example.com/file?query#frag')
395395
end
396396

397+
it "returns 'some:file' with 'http://example.com/some:file'" do
398+
assert_equal 'some:file', url.relative_path_to('http://example.com/some:file')
399+
end
400+
401+
it "returns 'some:file' with 'http://example.com/some:file?query#frag'" do
402+
assert_equal 'some:file', url.relative_path_to('http://example.com/some:file?query#frag')
403+
end
404+
397405
it "returns nil with '/file'" do
398406
assert_nil url.relative_path_to('/file')
399407
end

0 commit comments

Comments
 (0)