Skip to content

Auto-sanitize + gate translation quote artifacts#355

Merged
eandreeva-twr merged 1 commit into
mainfrom
fix/translation-quote-sanitizer
Jun 5, 2026
Merged

Auto-sanitize + gate translation quote artifacts#355
eandreeva-twr merged 1 commit into
mainfrom
fix/translation-quote-sanitizer

Conversation

@eandreeva-twr
Copy link
Copy Markdown
Collaborator

Summary

Auto-translation periodically emits nested unescaped double-quotes that break the production deploy. This happened three times in quick succession on main and recurs whenever a translated source article changes, because the translator wraps UI terms in " even when the English source uses single quotes (or none). A one-off locale fix never sticks.

Two failure classes, two pipeline stages:

  • JSX string attributes, e.g. alt="配置了"打开 URL"操作" → MDX parse error (caught today by check-mdx-parse).
  • Double-quoted YAML frontmatter scalars, e.g. description: "…"显示所有方案"…" → frontmatter YAML error (previously only caught by the slow Astro build).

Changes

  • scripts/lint-mdx.mjs — new fixable nested-quote rule. Converts raw inner "' in JSX attributes and frontmatter scalars, with fix-then-verify: it only writes the repair if the result parses cleanly; otherwise it leaves the file and reports it so the strict gate blocks it. Code-fence-aware; recognizes valued/boolean attributes, {…} expressions, and tag close so it never touches valid content. Auto-repairs in the translate apply job (which already runs lint-mdx --fix) and acts as a strict deploy gate for free.
  • scripts/check-mdx-parse.mjs — validates frontmatter YAML (the gap that let bad-YAML translations reach the build), reporting file:line at the fast pre-build gate.
  • Both scripts refactored behind a run-directly guard so their logic is importable; added node:test unit tests.

No workflow files changed — the existing wiring (lint-mdx --fix in translate, strict lint-mdx + check-mdx-parse at deploy) picks both up automatically.

Test Plan

  • node --test 'scripts/__tests__/*.test.mjs' → 14/14 pass (frontmatter fixer, JSX fixer incl. boolean-attr/code-fence cases, combiner, parsesClean fix-then-verify, frontmatter validator)
  • node scripts/lint-mdx.mjsall files OK (zero false positives across the full tree)
  • node scripts/lint-mdx.mjs --fix → no modifications on the clean tree
  • node scripts/check-mdx-parse.mjs → 3378 files parsed cleanly
  • Re-introduced both real breaks: lint-mdx detects + --fix repairs the JSX one; check-mdx-parse flags the frontmatter one with correct file:line

🤖 Generated with Claude Code

Auto-translation periodically emits nested unescaped double-quotes that
break the deploy: inside JSX string attributes (caught by check-mdx-parse)
and inside double-quoted YAML frontmatter scalars (previously only caught
by the slow Astro build). Both recur whenever a source article changes and
is re-translated, so a one-off locale fix never sticks.

- lint-mdx.mjs: new fixable `nested-quote` rule. Converts raw inner " to '
  in JSX attributes and frontmatter scalars, with fix-then-verify (only
  writes when the result parses; otherwise leaves it for the strict gate).
  Runs as auto-fix in the translate apply job and as a strict deploy gate
  for free. Code-fence-aware; never touches valid content.
- check-mdx-parse.mjs: validate frontmatter YAML (the gap that let bad-YAML
  translations reach the build), reporting file:line at the fast gate.
- Both scripts refactored behind a run-directly guard so their logic is
  importable; add node:test unit tests (14 cases).
@eandreeva-twr eandreeva-twr merged commit 106a5aa into main Jun 5, 2026
2 checks passed
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