Skip to content

Fix RELAX NG validation of documents with XML declarations - #380

Open
FFspiky wants to merge 3 commits into
ruby:masterfrom
FFspiky:fix/relaxng-xml-declaration-241
Open

FFspiky wants to merge 3 commits into
ruby:masterfrom
FFspiky:fix/relaxng-xml-declaration-241

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 16, 2026 •

Copy link
Copy Markdown

Documents with XML declarations fail RELAX NG validation on :xmldecl. The multiline example in #241 also emits whitespace before and after the root, which the validator incorrectly treats as element content.

Handle the declaration and root-external XML whitespace in RelaxNG#receive. Skip comments, processing instructions, and DTD declarations so markup before, inside, or after the root does not advance the schema. Use the existing attribute stack to identify element nesting, initialize it for validation without an initial reset, and retain its existing reset behavior. Whitespace inside elements still reaches schema validation, including text and exact value patterns. The shared Validator is unchanged.

Fixes #241.

Regressions preserve the issue's original schema and multiline document verbatim, and cover declaration variants, string and IO sources, leading/trailing whitespace with and without declarations, first use without reset, repeated resets, and resetting an unfinished document. They also check that incorrect roots/children, missing required children, mismatched text values, and non-XML whitespace outside the root are rejected.

Validation on macOS arm64 / Ruby 3.4.9:

  • Targeted suite against the original upstream implementation: 32 tests, 168 assertions, 8 expected failures. With this fix: 32 tests, 207 assertions, no failures/errors on the initial fix. The two additional regressions from review both fail on 3ed87be and pass on 1a90d7c. The current targeted suite passes all 34 tests and 218 assertions.
  • bundle exec rake test: 852 tests, 2744 assertions, no failures/errors, 5 omissions.
  • bundle exec rake test RUBYOPT=--enable-frozen-string-literal: the same result.
  • Built and locally installed the gem, verified the installed library path and content, and ran the copied test suite against it: the same result.
  • bundle exec rake warning:error clobber_rdoc rdoc and git diff --check: pass.

The five omissions are the repository's Ruby < 4.0 Ractor exclusions. Bundler 2.6.9 required BUNDLE_DISABLE_EXEC_LOAD=true for this non-ASCII installation path. Other Ruby versions and the Linux/Windows/JRuby matrix have not been run locally.

AI assistance: OpenAI Codex generated the implementation, tests and this description, and ran the listed checks. No human review is claimed.

@FFspiky

FFspiky commented Nov 16, 2026

Copy link
Copy Markdown
Author

The Test workflow currently reports action_required with no jobs started. Could a maintainer approve it for this PR? The Ruby 3.4.9 local full, frozen-string and installed-gem test results are recorded above; the hosted Ruby/platform matrix is still unverified.

This follow-up was prepared with Codex.

Comment thread lib/rexml/validation/relaxng.rb Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RELAX NG Validator fails to handle XML documents with XML declaration

2 participants