Selaa lähdekoodia

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

nucular 9 vuotta sitten
vanhempi
commit
034ecfae72
2 muutettua tiedostoa jossa 9 lisäystä ja 1 poistoa
  1. 1 1
      lib/docs/core/url.rb
  2. 8 0
      test/lib/docs/core/url_test.rb

+ 1 - 1
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
 

+ 8 - 0
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