Module: Moxml::Adapter::CustomizedOga::EntityDecoderOverride
- Defined in:
- lib/moxml/adapter/customized_oga/entity_decoder.rb
Overview
Override Oga::EntityDecoder.decode for XML inputs.
Oga 3.4's stock Oga::XML::Entities.decode runs multiple passes, turning the well-formed "&" into "&" rather than the spec-correct "&". XML 1.0 §4.6 forbids recursive resolution of parsed entities — exactly one decode pass is correct.
Moxml::Adapter::Base.decode_entities does the single pass. HTML inputs fall through to Oga's stock HTML::Entities.decode, which has HTML-specific legacy rules that differ from XML's.
Prepending on the singleton class means every Oga reader (Text#text, Attribute#value, etc.) automatically picks up the fixed decoder, so the adapter no longer needs to walk the parsed tree rewriting @text/@value ivars behind Oga's back.
Instance Method Summary collapse
-
#decode(input, html = false) ⇒ Object
rubocop:disable-next Style/OptionalBooleanParameter -- must match Oga's signature.
Instance Method Details
#decode(input, html = false) ⇒ Object
rubocop:disable-next Style/OptionalBooleanParameter -- must match Oga's signature
25 26 27 28 29 |
# File 'lib/moxml/adapter/customized_oga/entity_decoder.rb', line 25 def decode(input, html = false) return super if html ::Moxml::Adapter::Base.decode_entities(input) end |