Repository navigation
fix(admin): never render catalogue text as HTML, and guard the call sites - #230
Merged
Merged
Conversation
…ites Two gaps the catalogue tests cannot see, both from the #217 review. 1. `{@html $t('layout.reportDialog.descriptionHtml')}` in +layout.svelte rendered catalogue content as markup, while catalog.ts claims the opposite and the guard in catalog.test.ts only rejected `<a` and `href=`. An `<img src=x onerror=...>` in a future locale file would have passed every test and executed in an operator's admin session. Community locale PRs are a real input here, so that is a live surface, not a theoretical one. The HTML key was also redundant: `description` already existed, plain and unused, with the same sentence. The dialog now uses it and `descriptionHtml` is deleted from en and fr, so the contract in catalog.ts is true again without needing a rule to enforce it. 2. Nothing checked the call sites against the catalogue. A typo rendered the dotted key on screen and CI stayed green. frontend/scripts/check-i18n.mjs (pnpm check:i18n, run in CI) now enforces both: every literal key passed to $t/tr/trp/trp2 exists in en.json; plural group paths count as keys because trp appends `.one`/`.other` itself; dynamic template and ternary keys are counted and skipped rather than guessed at; and no call site renders catalogue text with {@html}. Verified: the guard passes on this tree (1503 call sites, 1323 keys, 299 plural groups, 11 dynamic skipped). A probe file containing a missing $t key, a missing tr key and one {@html} call makes it exit 1 and report all three, so the gate fails when it should. svelte-check is clean and the 27 visual tests pass.
Contributor
There was a problem hiding this comment.
ℹ️ No critical issues — one minor gap in the new guard, inline.
Reviewed changes
- Catalogue text no longer rendered as HTML —
+layout.sveltenow uses the plainlayout.reportDialog.descriptionkey, anddescriptionHtmlis deleted fromen.jsonandfr.json. The only remaining{@html}insrc/isitem.icon(lucide markup), and en/fr key parity still holds (catalog.test.ts, 22/22). - New
check-i18n.mjsgate — walkssrcfor literal$t/tr/trp/trp2keys, checks them againsten.jsonleaves plus plural group paths, and flags{@html}on a catalogue call. Verified locally: exits 0 at 1503 checked / 11 dynamic, and exits 1 with all three classes reported when probed. - CI wiring —
pnpm check:i18nruns aftersvelte-checkin thecheckjob, which is triggered onpull_request, so it is a real pre-merge gate.
deepseek-v4.1-flash | 𝕏
| // checked. | ||
| const CALL = /(?:\$t\(|\b(?:tr|trp|trp2)\()\s*(['"])((?:(?!\1).)+)\1/g; | ||
| const ANY_CALL = /(?:\$t\(|\b(?:tr|trp|trp2)\()/g; | ||
| const RENDERED_AS_HTML = /\{@html[^}]*?(?:\$t\(|\b(?:tr|trp|trp2)\()/; |
Contributor
There was a problem hiding this comment.
Because the scan is per line, a {@html whose expression wraps — {@html on one line, $t('…')} on the next — escapes this check entirely; I confirmed it with a probe file. The regex already crosses newlines via [^}]*?, so it is only the source.split('\n') above that hides it: matching against the whole source and deriving the line from the match index closes the gap.
Technical details
# `{@html}` guard misses wrapped expressions
## Affected sites
- `frontend/scripts/check-i18n.mjs:69-70` — `RENDERED_AS_HTML.test(line)` only ever sees one line of source.
- `frontend/scripts/check-i18n.mjs:59` — `RENDERED_AS_HTML` itself is fine for multi-line input; `[^}]*?` already spans newlines.
## Required outcome
- A `{@html` whose catalogue call sits on a following line is reported by `pnpm check:i18n`, anchored at the line of the `{@html`.
- Existing single-line detection and the `missing` / `dynamic` reporting stay unchanged.
## Suggested approach (optional)
- Leave the per-line loop as is, then run `RENDERED_AS_HTML` with the `/g` flag over the whole `source` and compute the line as `source.slice(0, match.index).split('\n').length`. Keep `[^}]*?` as the bound so code after the closing `}` cannot match.
## Verification
- Probe used: a `.svelte` file containing `<p>{@html\n $t('layout.reportDialog.description')}</p>`; the current script exits 0 on it.
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.

First two items from the #217 review, the two that can bite quietly.
1. Catalogue text was rendered as HTML
{@html $t('layout.reportDialog.descriptionHtml')}That contradicts the stated contract in
catalog.ts("never{@html}catalog content"), and the only guard wascatalog.test.ts, which rejects<aandhref=and nothing else. An<img src=x onerror=…>in a future locale file would have passed every test and executed in an operator's admin session. We accept community locale PRs, so this is a live surface.The HTML key was also redundant:
descriptionalready existed, plain, with the same sentence, and was unused. The dialog now uses it anddescriptionHtmlis gone fromen.jsonandfr.json, so the contract is true rather than merely enforced.2. Nothing checked the call sites
Roughly 1,500
$t/tr/trp/trp2calls, and no test that the keys they pass exist. A typo renders the dotted key on screen and CI stays green.frontend/scripts/check-i18n.mjs(pnpm check:i18n, run in CI after svelte-check) now enforces:en.json;trpappends.one/.otheritself;{@html}.Why a script and not a test: vitest here runs in browser mode, so
node:fsis unavailable, and thenode:testfile is excluded from CI. A CI step is the only place this check can actually run.Verification
The gate was proved to fail: a probe file with a missing
$tkey, a missingtrkey and one{@html}call made it exit 1 and report all three, and removing the probe returned it to 0.Also:
svelte-checkreports 0 errors and 0 warnings, and the visual suite passes 27/27.Not in this PR
The remaining review items: the bundle cost (both catalogues in one 143 KB chunk), the admin's strict en/fr parity blocking partial German/Polish,
pluralForm()limited toone/otherbefore Polish, thehour12: localeTag() !== 'fr'special case, and three French corrections. Separate PR, so this one stays reviewable.