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

Nokogiri::XML::Schema#validate behaves differently in MRI and JRuby #1282

Closed
ylansegal opened this issue May 6, 2015 · 4 comments · Fixed by #3258
Closed

Nokogiri::XML::Schema#validate behaves differently in MRI and JRuby #1282

ylansegal opened this issue May 6, 2015 · 4 comments · Fixed by #3258

Comments

@ylansegal
Copy link

When trying to re-use a Nokogiri::XML::Schema object for validating multiple Nokogiri::XML documents, the MRI and JRuby implementations behave differently. The JRuby implementation reports errors encountered in previous validation, while the MRI version does not.

Please see https://gist.github.com/ylansegal/eac88b27f5369b4f8ca7 for a recreation of the problem. It essentially validates a known good document, then a bad document and then a good document again against the same Schema object. In MRI, the last validation does not report errors (which is what I would expect). In JRuby it reports the errors from the previously validated document.

By the way, I encountered this error because the ruby-saml gem tries to memoize the schema to avoid reading from disk each time:

https://github.com/onelogin/ruby-saml/blob/master/lib/onelogin/ruby-saml/saml_message.rb#L26

@flavorjones
Copy link
Member

Thanks for reporting this. Someone will take a look!

zfletch added a commit to perseids-tools/epi-doc-validator-rb that referenced this issue Mar 9, 2021
There is a bug in Nokogiri
(sparklemotion/nokogiri#1282) that causes
`Nokogiri::XML::RelaxNG#validate` in JRuby to add errors every
time it's called.

To fix this, create a new instance of `Nokogiri::XML::RelaxNG` every
time. To lessen the impact on the library's performance, use
`from_document` and cache the parsed XML.
@flavorjones flavorjones added this to the v1.13.0 milestone Aug 19, 2021
@flavorjones
Copy link
Member

Just a note that I've started a branch to clean up XML::Schema behavior and this is being worked on.

@ylansegal
Copy link
Author

👏 👏 Thank you @flavorjones. Better late than never!

@flavorjones
Copy link
Member

See #3258 which should fix this.

flavorjones added a commit that referenced this issue Jun 24, 2024
…3258)

**What problem is this PR intended to solve?**

Fixes #1282

**Have you included adequate test coverage?**

Yes.

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

Brings the JRuby impl in line with the CRuby impl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants