fix: normalize category elements with attributes to plain strings - #307
Open
pratik-desgn wants to merge 1 commit into
Open
fix: normalize category elements with attributes to plain strings#307pratik-desgn wants to merge 1 commit into
pratik-desgn wants to merge 1 commit into
Conversation
index.d.ts declares Item.categories as string[], but xml2js returns
{_, $} objects for any <category> element that has attributes (e.g.
domain="..."), since item.categories was set directly from the raw
xml2js output with no normalization. Extract the text value the same
way item.guid already does, so categories is always string[]
regardless of whether the source XML's <category> tags carry
attributes.
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 #289.
index.d.tsdeclaresItem.categoriesasstring[], butxml2jsreturns a{_, $}object for any<category>element that has attributes (e.g.domain="..."), sinceitem.categorieswas being set directly from the rawxml2jsoutput with no normalization:For a feed like:
categoriescame out as:instead of
['Release', 'copilot']as declared.Fix
Extract the text value the same way
item.guidalready does a few lines above:This normalizes both shapes (plain string categories and
{_, $}categories-with-attributes) to plain strings, matching the declared type.Testing
test/input/item-category-with-attrs.rss+ golden output, reproducing the exact shape from the issue (mixed attributed/plain<category>tags) — confirmed this test fails on the old code with the exact reported shape, passes with the fix.heraldsun,guardian) that happened to already contain<category domain="...">elements and had the buggy{_, $}shape baked into their snapshots — diffed to confirm the change is scoped to exactly thecategoriesfield, nothing else.