Skip to content

test: escape placeholder values in the translate() mock, matching real behaviour - #136

Open
moodyjmz wants to merge 1 commit into
mainfrom
test/escape-translate-stub
Open

test: escape placeholder values in the translate() mock, matching real behaviour#136
moodyjmz wants to merge 1 commit into
mainfrom
test/escape-translate-stub

Conversation

@moodyjmz

Copy link
Copy Markdown
Contributor

Real translate() escapes every placeholder value by default (escape-html), but the shared vitest.setup.ts mock did naive substitution with no escaping — so any spec asserting on translated, placeholder-interpolated text passed regardless of whether the real string would come out double-escaped in a context that doesn't expect it (an ARIA attribute, for one).

Found reviewing #125, where this exact gap hid a real bug (an owner display name containing &/</>/quotes producing a mangled accessible name — invisible to the test because the mock never escaped it).

Adds escape-html + @types/escape-html as devDependencies (same versions @nextcloud/l10n itself uses), and a small dedicated spec (src/test-utils/translateMock.spec.ts) pinning the mock's contract, rather than relying on each feature spec to happen to cover it.

Verified: npm run test:unit (85/85 passing, up from 83 — no existing test relied on the unescaped behavior), npm run lint, npm run stylelint, npm run build (byte-identical output, confirming this is test-only).

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…l behaviour

Real translate() escapes every placeholder value by default (escape-html),
but the shared vitest.setup.ts mock did naive substitution with no
escaping — so any spec asserting on translated, placeholder-interpolated
text passed regardless of whether the real string would come out
double-escaped in a context that doesn't expect it (an ARIA attribute,
for one). Found reviewing #125, where this exact gap hid a real bug.

Pin the mock's contract with a small dedicated spec rather than relying
on each feature spec to happen to cover it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
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