XML::Schema#validate(filename) returns 0 errors for malformed documents #642

Open
bts opened this Issue Mar 27, 2012 · 2 comments

Comments

Projects
None yet
2 participants

bts commented Mar 27, 2012

It seems that Nokogiri::XML::Schema#validate for filenames (not Nokogiri::XML::Documents) does not return any errors for malformed XML documents: only for well-formed documents that do not conform to the provided schema.

require 'nokogiri'

Nokogiri::VERSION
# => "1.5.3.rc3"

RUBY_VERSION
# => "1.9.3"

bad_xml_data = 'xyz'
xsd_data = <<-XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.example.org/contactExample"
  xmlns:tns="http://www.example.org/contactExample"
  elementFormDefault="qualified">
  <xs:element name="Contacts"></xs:element>
</xs:schema>
XSD

malformed_xml_path = '/tmp/malformed.xml'

File.open(malformed_xml_path, 'w') { |f| f.write(bad_xml_data) }
# => 3

schema = Nokogiri::XML::Schema.new(xsd_data)
# => #<Nokogiri::XML::Schema:0x007feea9c40c80>

schema.validate(malformed_xml_path)
# => []

schema.valid?(malformed_xml_path)
# => true
Owner

flavorjones commented Mar 28, 2012

Investigating.

Owner

flavorjones commented Feb 17, 2016

This is still a valid bug, and we should probably figure out how to better handle this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment