Merge pull request #15 from G5/drop-the-base

Don't explode when a rel attribute exists without a base tag.
This commit is contained in:
Don Petersen 2013-10-09 10:20:36 -07:00
commit 56383a0a91
3 changed files with 23 additions and 1 deletions

View file

@ -110,7 +110,7 @@ module Microformats2
end end
def absolutize(href) def absolutize(href)
if URI.parse(href).absolute? if URI.parse(href).absolute? || @base.nil?
href href
else else
URI.join(@base, href).to_s URI.join(@base, href).to_s

View file

@ -190,6 +190,17 @@ describe Microformats2::Collection do
end end
end end
end end
describe "rels-that-drop-the-base.html" do
before do
html = "spec/support/lib/microformats2/rels-that-drop-the-base.html"
@collection = Microformats2.parse(html)
end
it "keeps the relative path" do
@collection.to_hash[:rels]["stylesheet"].should eq([ "/path/to/stylesheet.css" ])
end
end
end end

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Rels without Base Test</title>
<link href="/path/to/stylesheet.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<li><a rel="met friend" href="http://adactio.com/">Jeremy Keith</a></li>
<li><a rel="met friend" href="http://tantek.com/">Tantek Çelik</a></li>
</body>
</html>