Capture unknown elements into one extension tree - #334
Open
mmcdole wants to merge 2 commits into
Open
Conversation
Unknown elements were handled three inconsistent ways: namespaced ones became the ext.Extension tree, non-namespaced item children went into the flat Item.Custom map (dropping nesting, attributes and repetition), and unknown elements at channel, atom feed, entry and source level were skipped and lost. shared.ParseCustom now parses any unrecognized non-namespaced element with the same recursive builder namespaced extensions use and files it under the _custom pseudo namespace. The rss channel and item parsers and the atom feed, entry and source parsers capture through it; the RSS 1.0 <items> rdf:Seq stays skipped since it is a structural list of references, not content. Item.Custom is kept as a compatibility shim fed from the tree: childless elements keep their flat value (entity-decoded as before, last wins), and nested elements no longer corrupt it, they live fully formed in the tree instead. Feed and Item gain GetExtension, GetExtensionValue and GetCustomValue accessors. Existing fixture output changes are purely additive: 82 added lines of extensions across four fixtures, no removed or altered values. New fixtures cover channel level customs, attributes, repetition, CDATA, nesting, custom-plus-extension mixes, and atom feed and entry customs. Fixes #276 Fixes #203 Fixes #82
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #334 +/- ##
==========================================
+ Coverage 79.75% 79.82% +0.06%
==========================================
Files 22 23 +1
Lines 1912 1948 +36
==========================================
+ Hits 1525 1555 +30
- Misses 298 302 +4
- Partials 89 91 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #276. Fixes #203. Fixes #82.
Unknown elements were handled three inconsistent ways: namespaced elements became the recursive
ext.Extensiontree, non-namespaced item children went into the flatItem.Custommap (dropping nesting, attributes and repetition, which is #203's corruption and #82's missing data), and unknown elements at channel level, atom feed, entry and source level were skipped and lost entirely.This lands the #276 plan in its v1-additive form:
shared.ParseCustomparses any unrecognized non-namespaced element with the same recursive builder namespaced extensions already use, and files it under the_custompseudo namespace, preserving nesting, attributes and repetition. After Route the parser element loops through one shared helper #333 the capture point was onedefault:case per container, so the wiring is one line each in the rss channel/item and atom feed/entry/source parsers. The RSS 1.0<items>rdf:Seq stays skipped: it is a structural list of item references, not content.Item.Customstays as a compatibility shim fed from the tree. Childless elements keep their flat value exactly as before (entity-decoded, last one wins); nested elements no longer produce corrupted flat text, they live fully formed in the tree. The field is documented as deprecated in favor of the tree; removal waits for v2.FeedandItemgainGetExtension,GetExtensionValueandGetCustomValueaccessors (the ergonomic layer from the oldv2-custom-elementsbranch, adapted). That branch's parser approach was not used: it captured customs with flatParseText, so it relocated the corrupted / mangled nested custom XML #203 corruption rather than fixing it.Behavior notes: everything here is additive. Four existing fixtures gain
extensions._customblocks (82 added lines, zero removed or changed values,custommaps byte-identical). Data that was previously discarded (channel-level and atom-level unknowns) now appears inExtensions; feeds without unknown elements produce identical output.Tests: nine new fixture pairs (channel-level customs, attributes, repetition, CDATA, nesting, custom-plus-extension mixes, atom feed and entry customs, and a nested-with-CDATA case reproducing #203) plus an accessor unit test covering namespaced lookups, feed and item custom values, repetition, nested children, the shim's childless-only contract, and absent-key behavior.