diff --git a/lib/microformats2/collection.rb b/lib/microformats2/collection.rb index 875acc4..990d84f 100644 --- a/lib/microformats2/collection.rb +++ b/lib/microformats2/collection.rb @@ -110,11 +110,15 @@ module Microformats2 end def absolutize(href) - if URI.parse(href).absolute? || @base.nil? - href + uri = URI.parse(href) + + if uri.scheme || @base.nil? + uri = uri.normalize else - URI.join(@base, href).to_s + uri = URI.join(@base, href) end + + uri.to_s end end end diff --git a/spec/lib/microformats2/collection_spec.rb b/spec/lib/microformats2/collection_spec.rb index 9aa62af..0b0bda1 100644 --- a/spec/lib/microformats2/collection_spec.rb +++ b/spec/lib/microformats2/collection_spec.rb @@ -191,6 +191,17 @@ describe Microformats2::Collection do end end + describe "rels-with-unnormalized-urls.html" do + before do + html = "spec/support/lib/microformats2/rels-with-unnormalized-urls.html" + @collection = Microformats2.parse(html) + end + + it "should normalize the url" do + @collection.to_hash[:rels]["me"].should eq([ "http://jessicard.com/" ]) + end + end + describe "rels-that-drop-the-base.html" do before do html = "spec/support/lib/microformats2/rels-that-drop-the-base.html" diff --git a/spec/support/lib/microformats2/rels-with-unnormalized-urls.html b/spec/support/lib/microformats2/rels-with-unnormalized-urls.html new file mode 100644 index 0000000..d0a566c --- /dev/null +++ b/spec/support/lib/microformats2/rels-with-unnormalized-urls.html @@ -0,0 +1,11 @@ + + +
+