Make SAX parsing consistent on all adapters - #83
Open
HassanAkbar wants to merge 8 commits into
Open
Conversation
HassanAkbar
force-pushed
the
xml-numeric-entities-parsing
branch
from
May 25, 2026 12:12
ac7d147 to
1a14522
Compare
HassanAkbar
force-pushed
the
xml-numeric-entities-parsing
branch
4 times, most recently
from
June 5, 2026 14:41
f80e6e7 to
6c68008
Compare
HassanAkbar
marked this pull request as ready for review
June 5, 2026 14:42
- nokogiri.rb, libxml.rb: replace misleading bareword Nokogiri.decode_entities / Libxml.decode_entities with Moxml::Adapter::Base.decode_entities. The bareword relied on Ruby constant resolution to find the adapter class (which inherits the class method from Base), not the gem module, but reads as a gem call. The explicit receiver removes ambiguity. - base.rb: freeze ENTITY_DECODE_RE and mark it private_constant, matching the treatment of NAMED_ENTITY_DECODE_MAP. - customized_libxml/node.rb: narrow attr_accessor :native to attr_reader :native plus a private native= writer. Only replace_native_verbatim sets this; making it publicly mutable lets any caller swap the wrapper underlying node from anywhere.
ronaldtse
force-pushed
the
xml-numeric-entities-parsing
branch
from
June 25, 2026 11:38
6c68008 to
32ff836
Compare
…wrapper The previous audit fix narrowed attr_accessor :native to a private writer. That broke replace_native_verbatim in the libxml adapter because the call site lives in a different class. Replace the private generic setter with a public semantic method replace_native! that expresses the actual operation: swap the underlying native node after libxml-ruby content= would have silently re-escaped stored text.
Oga 3.4's stock entity decoder runs multiple passes, turning well-formed `&` into `&` rather than the spec-correct `&` (XML 1.0 §4.6 forbids recursive resolution of parsed entities). The previous fix walked the parsed tree, read raw @text/@value ivars, decoded once, and wrote the result back via instance_variable_set — the exact pattern forbidden by the project's global rules. Two CustomizedOga override modules now handle both paths without any ivar access on foreign objects: - EntityDecoderOverride prepends Oga::EntityDecoder.singleton_class and routes XML reads through Base.decode_entities for a single decode pass (HTML still falls through to Oga's stock decoder, which has HTML-specific legacy rules). - RawValueOverride prepends Oga::XML::Attribute and Oga::XML::Text and consults the NativeAttachment sidecar first. User-authored values are stored as :raw_value / :raw_text sidecar entries and returned verbatim, bypassing the lazy decoder; parsed values fall through to Oga's normal lazy read, which the EntityDecoderOverride makes single-pass. With both overrides in place, the post-parse `decode_entities_in_tree!` walk and its `mark_decoded` / `write_decoded` ivar-writing helpers are redundant and are removed. All entity state for user-authored nodes lives in NativeAttachment; parsed nodes get correct single-pass lazy decoding transparently. All 2150 Oga-related specs pass (sax_entity_parity, integration, oga_spec, entity_restoration).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is for addressing lutaml/lutaml-model#641
Status matrix
main:current:Actual outputs (per adapter)
nokogiri
ox
oga
rexml
libxml