Ignore invalid language tags in vocab parsing#848
Conversation
Generated vocabulary parsers now validate language tags before constructing LanguageString values. Malformed remote language-map entries are skipped like other undecodable scalar values, while valid entries still parse normally. Fixes fedify-dev#847 Assisted-by: Codex:gpt-5.5
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@codex review |
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where malformed language tags in remote JSON-LD language maps caused parsing to abort with a RangeError. It introduces a helper function isValidLanguageTag using Intl.Locale to validate language tags, integrates this check into the scalar type data validation, and adds a test case to ensure malformed tags are gracefully ignored. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cfdea25b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Malformed language-map entries are dropped during decoding, but the parsed object could still keep the original JSON-LD cache and return those entries from a default toJsonLd() call. Track whether any decoded value was skipped and carry that state through subclass parsing so objects only reuse the original JSON-LD when it still matches the accepted decoded values. fedify-dev#848 (comment) Assisted-by: Codex:gpt-5.5
|
@codex review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where malformed language tags in remote JSON-LD language maps caused parsing to abort with a RangeError. It introduces a helper function isValidLanguageTag using Intl.Locale to validate language tags, skips caching the original JSON-LD if any properties fail to decode, and adds a test case to verify that malformed language tags are ignored while the rest of the object is successfully parsed. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c18ea8f27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A child vocabulary object can reject malformed language-map values while decoding, which makes its original JSON-LD cache unsafe to reuse. Carry that cache state back to the parent decoder before storing the decoded child so parse-then-serialize paths do not re-emit skipped nested values from the parent's cached payload. fedify-dev#848 (comment) Assisted-by: Codex:gpt-5.5
|
@codex review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue in @fedify/vocab where malformed language tags in remote JSON-LD language maps would cause parsing to abort with a RangeError. It introduces a validation helper, isValidLanguageTag, using Intl.Locale, and updates the generated class decoder logic to skip caching when invalid or uncacheable values are encountered. Unit tests have been added to verify that malformed language tags are ignored both at the root level and within nested objects. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Why this patch handles the error in the parser
Remote JSON-LD can contain a language map key that
Intl.Localedoes not accept. Before this patch, the generated vocabulary parser still passed that key intonew LanguageString(...), so a malformed remote field could surface as aRangeErrorwhile parsing an inbox activity.The fix keeps
LanguageStringitself strict. Constructing one directly with an invalid tag should still fail, because that is useful feedback for local code. The generated parser has a different job: it is reading remote input and already skips scalar values that do not match any supported decoded shape. This patch makes invalid language tags follow that same path.How the parser now avoids the crash
The
rdf:langStringdata check in packages/vocab-tools/src/type.ts now requires the@languagevalue to be accepted byIntl.Localebefore emitting aLanguageStringconstructor call. packages/vocab-tools/src/class.ts emits the helper used by generated vocabulary classes.That helper catches only
RangeError, which is the error shape used for a bad locale identifier. Other errors still propagate. That keeps the fallback narrow: malformed remote language tags are treated as bad input, but unrelated programming or runtime errors are not hidden.The regression test in packages/vocab/src/vocab.test.ts uses a
Notewith a mixedcontentMap: one malformed language key and one validenkey. The valid entry still parses, and the malformed entry is ignored.Verification
I ran the targeted regression test first and confirmed that it failed with the old
RangeError. After the fix, these checks passed:deno task -f @fedify/vocab test --filter "Note.fromJsonLd() ignores malformed language tags"mise run test:update_snapshotsgit diff --checkmise run checkmise run test-each vocab-tools vocab