Skip to content

fix(translation): validate dictionaries before caching - #10

Draft
knowlet wants to merge 1 commit into
mainfrom
fix/validate-translation-dictionaries
Draft

knowlet wants to merge 1 commit into
mainfrom
fix/validate-translation-dictionaries

Conversation

@knowlet

@knowlet knowlet commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

The loader accepted JSON that is not a string-to-string translation dictionary. Non-string values can reach string rendering operations; JSON null replaced a working cached dictionary before Object.keys threw and reported failure.

  • Validate a non-null, non-array object whose values are strings before caching.
  • Reject invalid files through the existing failure callback without destroying the previous usable dictionary.
  • Preserve empty dictionaries, empty string translations and literal special keys.
  • Six production lines only; no selection-order, lookup, options, installer, dependency or workflow changes.

Verification

Summary by Sourcery

Validate translation dictionaries before caching to prevent malformed data from breaking rendering or replacing usable translations.

Bug Fixes:

  • Validate translation JSON as a non-null object with string values before caching it, preserving the last usable dictionary when invalid data is loaded.

Documentation:

  • Document the translation-file schema, validation behavior, cache preservation, and regression coverage.

Tests:

  • Add regression coverage for invalid translation shapes and valid empty or special-key dictionaries.

Summary by cubic

Fixes translation loading so invalid JSON files no longer replace a working dictionary or feed non-string values into string rendering.

The loader now validates that a translation file is a non-null, non-array object whose values are all strings before caching it. Files that fail validation go through the existing failure callback and leave the previous usable dictionary intact. Empty dictionaries, empty string translations, and literal keys like hasOwnProperty remain valid.

  • Added validation in DynamicTranslation.js and a regression test suite covering ten invalid shapes and two valid controls.
  • Documented the translation file schema in docs/research/translation-file-schema.md.

Written for commit c4bd843. Summary will update on new commits.

View guided diff Turn on auto-fix

Hosted verification completed

PR CI 43904797840 passed all three jobs: Node 18 and Node 20 each ran 80 passing Jest tests; Python 3.11 ran 27 passing installer tests. No reruns or skipped tests.

Job logs confirm checkout a9b8f3aa01cc07f9f24e700a4c1fa3c477549a46. Its verified parents are the stated base and head c4bd8430bc48c86ca4ebfd0bbb6bb7900d6fcf26; tree f89c7f8a6ace161b6d222c1263a990f3ee85fc16 equals the local tested/staged tree. All three remote modified files match the local content. This is verified PR merge-ref CI, not a separate bare-head push run.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Validate parsed translation dictionaries before caching so malformed values follow the failure path without replacing a usable dictionary.

  • DynamicTranslation.js L184-189

Documentation

Document the accepted translation-file format, the cache-preservation behavior, and the scope and verification of the fix.

  • docs/research/translation-file-schema.md L1-24

Tests

Exercise invalid dictionary shapes and valid controls, checking failure callbacks and preservation of the existing usable dictionary.

  • tests/TranslationSchema.test.js L1-47

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant