Skip to content

Preserve whitespace in /api/mask input - #186

Merged
sgasser merged 1 commit into
mainfrom
185-preserve-mask-whitespace
Nov 7, 2026
Merged

sgasser merged 1 commit into
mainfrom
185-preserve-mask-whitespace

Conversation

@sgasser

@sgasser sgasser commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Fixes #185

POST /api/mask validated text with z.string().trim().min(1). Zod's .trim() is a transform, so the handler detected and masked the trimmed text and returned masked without the input's leading or trailing whitespace. The browser extension aligns masked against the original prompt character by character, so a trailing \n (common in Gemini's editor) failed the check and was reported as "server didn't respond".

The schema now rejects blank text with a refine and passes text through unchanged. Empty and whitespace-only input still return 400 validation_error with "text is required".

Verification

  • New route test with " John Smith lives in Berlin\n\n": the detector receives the untrimmed text and masked keeps the surrounding whitespace. It fails on the previous schema and passes with the fix.
  • bun test (513 pass), bun run typecheck and bun run check pass.
  • Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Zod's .trim() transformed the validated text, so /api/mask detected and
masked the trimmed string and returned `masked` without the input's
leading or trailing whitespace. The browser extension aligns `masked`
against the original prompt and reported the mismatch as an unreachable
server. Reject blank text with a refine instead, leaving it unchanged.

Fixes #185
@sgasser
sgasser enabled auto-merge (squash) November 7, 2026 09:18
@sgasser
sgasser merged commit 5732aca into main Nov 7, 2026
3 checks passed
@sgasser
sgasser deleted the 185-preserve-mask-whitespace branch November 7, 2026 09:21
@sgasser sgasser mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant