From 034ecfae72f301519c570bd14668ffff8bf409ce Mon Sep 17 00:00:00 2001 From: nucular Date: Mon, 16 May 2016 03:02:40 +0200 Subject: [PATCH] Replace File.basename in URL#relative_path_to because it doesn't handle special characters in URLs well --- lib/docs/core/url.rb | 2 +- test/lib/docs/core/url_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/docs/core/url.rb b/lib/docs/core/url.rb index 62b474e1..b2eaf658 100644 --- a/lib/docs/core/url.rb +++ b/lib/docs/core/url.rb @@ -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 diff --git a/test/lib/docs/core/url_test.rb b/test/lib/docs/core/url_test.rb index 71464b9e..8dd187c5 100644 --- a/test/lib/docs/core/url_test.rb +++ b/test/lib/docs/core/url_test.rb @@ -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