Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Created October 6, 2011 04:04
Show Gist options
  • Select an option

  • Save freshtonic/1266497 to your computer and use it in GitHub Desktop.

Select an option

Save freshtonic/1266497 to your computer and use it in GitHub Desktop.
Nokogiri clobbers LibXML's error handlers
describe "Nokogiri & LibXML interaction" do
it "LibXML's error handler should not be clobbered by Nokogiri::XSLT(...)" do
malformed_xml = '<?xml version="1.0" encoding="utf-8"?>
<some_tag>
</some_tag_with_typo>'
xslt = '<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="product">
</xsl:template>'
begin
# Comment out this line and the spec passes.
Nokogiri::XSLT(StringIO.new(xslt))
rescue Exception
end
errors = []
LibXML::XML::Error.set_handler do |foo|
errors << foo
end
reader = LibXML::XML::Reader.io(StringIO.new(malformed_xml))
begin
while reader.read
end
rescue
end
errors.size.should == 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment