Skip to content

Commit

Permalink
Merge pull request #805 from lcdhoffman/master
Browse files Browse the repository at this point in the history
Fix EmptyStackException thrown by nokogiri-java when an xlink:href attribute shows up with an empty XmlBaseStack
  • Loading branch information
flavorjones committed Mar 19, 2013
2 parents 05eff2f + 6dc3379 commit 095016f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ext/java/nokogiri/internals/ReaderNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,12 @@ private String getXmlBaseUri(String n, String v, Stack<String> xmlBaseStack) {
else return base.concat("/").concat(v);
}
} else if ("xlink:href".equals(n)) {
if (v.startsWith("http://")) {
return v;
} else if (!xmlBaseStack.isEmpty()) {
String base = xmlBaseStack.peek();
if (base.endsWith("/")) return base.concat(v);
else return base.concat("/").concat(v);
return base;
}
}
return null;
}
Expand Down
33 changes: 33 additions & 0 deletions test/test_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,39 @@ def test_base_uri
reader.map {|n| n.base_uri })
end

def test_xlink_href_without_base_uri
reader = Nokogiri::XML::Reader(<<-eoxml)
<x xmlns:xlink="http://www.w3.org/1999/xlink">
<link xlink:href="#other">Link</link>
<other id="other">Linked Element</other>
</x>
eoxml

reader.each do |node|
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
if node.name == 'link'
assert_nil node.base_uri
end
end
end
end

def test_xlink_href_with_base_uri
reader = Nokogiri::XML::Reader(<<-eoxml)
<x xml:base="http://base.example.org/base/"
xmlns:xlink="http://www.w3.org/1999/xlink">
<link xlink:href="#other">Link</link>
<other id="other">Linked Element</other>
</x>
eoxml

reader.each do |node|
if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
assert_equal node.base_uri, "http://base.example.org/base/"
end
end
end

def test_read_from_memory
called = false
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
Expand Down

0 comments on commit 095016f

Please sign in to comment.