Skip to content

Empty string does not fail schema validation with JRuby like it does with MRI #783

@mrkcor

Description

@mrkcor

With Nokogiri 1.5.5 on JRuby validating an empty document does not result in an error, while with MRI it does.

If you try the below snippet in MRI and JRuby (XML schema taken from #642, perhaps there is some relation between the issues -- atleast for JRuby):

require 'nokogiri'

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

xsd = Nokogiri::XML::Schema.new(xsd_data)

empty_xml = Nokogiri::XML("")

xsd.validate(empty_xml)
#=> MRI: [#<Nokogiri::XML::SyntaxError: The document has no document element.>]
#=> JRuby: []

xsd.valid?(empty_xml)
#=> MRI: false
#=> JRuby: true

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions