Skip to content

Commit

Permalink
fix(jruby): empty document should fail validation
Browse files Browse the repository at this point in the history
Brings the behavior in line with CRuby's impl.

Closes #783.
  • Loading branch information
flavorjones committed Jun 24, 2024
1 parent 73d9f35 commit 4a1cf8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA
* [CRuby] libgumbo correctly prints nonstandard element names in error messages. [#3219] @stevecheckoway
* [JRuby] Fixed some bugs in how `Node#attributes` handles attributes with namespaces. [#2677, #2679] @flavorjones
* [JRuby] Fix `Schema#validate` to only return the most recent Document's errors. Previously, if multiple documents were validated, this method returned the accumulated errors of all previous documents. [#1282] @flavorjones
* [JRuby] Fix `Schema#validate` to not clobber the `@errors` instance variable. [#1282] @ flavorjones
* [JRuby] Fix `Schema#validate` to not clobber the `@errors` instance variable. [#1282] @flavorjones
* [JRuby] Empty documents fail schema validation as they should. [#783] @flavorjones


### Changed
Expand Down
4 changes: 4 additions & 0 deletions ext/java/nokogiri/XmlSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ public class XmlSchema extends RubyObject
protected void
validate(Document document) throws SAXException, IOException
{
if (document.getDocumentElement() == null) {
throw new SAXException("Document is empty");
}

DOMSource docSource = new DOMSource(document);
validator.validate(docSource);
}
Expand Down
6 changes: 2 additions & 4 deletions test/xml/test_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ class TestNokogiriXMLSchema < Nokogiri::TestCase

it "validate_empty_document" do
doc = Nokogiri::XML("")
assert(errors = xsd.validate(doc))

pending_if("https://github.com/sparklemotion/nokogiri/issues/783", Nokogiri.jruby?) do
assert_equal(1, errors.length)
end
assert(errors = xsd.validate(doc))
assert_equal(1, errors.length)
end

it "valid?" do
Expand Down

0 comments on commit 4a1cf8e

Please sign in to comment.