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

Open
ylansegal opened this issue May 6, 2015 · 3 comments · May be fixed by #2316
Open

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

ylansegal opened this issue May 6, 2015 · 3 comments · May be fixed by #2316

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 flavorjones linked a pull request Aug 24, 2021 that will close this issue
@flavorjones flavorjones linked a pull request Aug 24, 2021 that will close this issue
@flavorjones flavorjones modified the milestones: v1.13.0, v1.14.0 Jan 6, 2022
@flavorjones flavorjones modified the milestones: v1.14.0, v1.15.0 Aug 28, 2022
@flavorjones flavorjones modified the milestones: v1.15.0, v1.16.0 Apr 28, 2023
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.

2 participants