Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mrkcor opened this issue Oct 31, 2012 · 4 comments · Fixed by #3260
Closed

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

mrkcor opened this issue Oct 31, 2012 · 4 comments · Fixed by #3260

Comments

@mrkcor
Copy link

mrkcor commented Oct 31, 2012

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
@ahmeij
Copy link

ahmeij commented Nov 1, 2012

Same behavior happens with 1.5.6.rc2

@akiellor
Copy link

Confirmed with nokogiri 1.5.9 and jruby 1.7.3.

@flavorjones
Copy link
Member

I've create #2641 which includes a pending (on JRuby) test that captures the issue.

I looked into this and I wasn't able to find the root cause -- but I traced enough to verify that javax.xml.validation.Validator isn't calling the SchemaErrorHandler at all in this case. It's not clear to me if that's a bug in the implementation or not, but I do know that I need help from someone who can dig deeper into the Java internals.

@flavorjones flavorjones modified the milestones: v1.14.0, v1.15.0 Aug 29, 2022
@flavorjones flavorjones modified the milestones: v1.15.0, v1.16.0 Apr 28, 2023
flavorjones added a commit that referenced this issue Jun 24, 2024
Brings the behavior in line with CRuby's impl.

Closes #783.
@flavorjones
Copy link
Member

PR #3260 will fix this.

flavorjones added a commit that referenced this issue Jun 24, 2024
**What problem is this PR intended to solve?**

Brings the behavior in line with CRuby's impl.

Closes #783.

**Have you included adequate test coverage?**

Yes. Test from #2641.

**Does this change affect the behavior of either the C or the Java
implementations?**

Bring Java in line with CRuby.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants