[GH-ISSUE #2959] [Issue]: A no-op edit-save can rewrite the whole message (curly quotes, trimmed whitespace); empty edit saves a blank message #1534

Closed
opened 2026-10-21 05:38:23 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2959

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The "did the user actually change anything?" check on an edit save compares the transformed edit value against the untransformed stored content. Because those two baselines differ, a save that the user intended as a no-op can still fire and rewrite the message:

  • With typographic quotes enabled, opening an edit and pressing Save without typing anything converts all the message's straight quotes to curly quotes in storage. A downstream regex/macro that matched straight quotes then silently stops matching.
  • A message with trailing whitespace/newlines gets that whitespace stripped on a no-op save (the saved value is trimmed, the baseline isn't).
  • Separately, clearing the textarea and saving persists a blank message.

How to reproduce (try it yourself)

Typographic quotes:

  1. Settings → enable typographic quotes (default is "straight").
  2. Have a message whose stored content has straight quotes, e.g. "hello" (typical AI output).
  3. Open edit, type nothing, press Save.
    You'll see: stored content becomes “hello” (curly). A regex/macro matching " no longer matches.
    Expected: a no-op save changes nothing.

Whitespace / empty:

  • Open edit on a message with trailing newlines, change nothing, Save → the trailing whitespace is gone.
  • Open edit, delete all text, Save → an empty message is saved and renders blank.
    Expected: no-op preserves content; empty save is rejected (or confirmed).

Where it is

packages/client/src/components/chat/ChatMessage.tsx — the textarea is seeded with formatTextQuotes(initialContent, quoteFormat) (307) and handleSave re-runs formatTextQuotes (300), but the change guard compares against raw content: if (content.trim() !== message.content) (1345). Same shape in packages/client/src/components/chat/ConversationMessage.tsx: val = formatTextQuotes(editValueRef.current.trim(), quoteFormat) then if (val !== editSourceContent) (454-455), where editSourceContent is the raw, untrimmed source (426). The server (chats.routes.ts:1651 → updateMessageContent) stores whatever it's given, with no empty/length check. formatTextQuotes is in packages/shared/src/utils/quote-format.ts.

What's happening

The textarea value is normalized (curly quotes, trimmed) while the no-op baseline is the raw stored content, so any quote-style or trailing-whitespace difference makes a no-op look like a change and persists the wholesale transform. There's also no guard against saving empty content.

Suggested fix

Compare like-for-like: gate the save on formatTextQuotes(rawSource, quoteFormat).trim() !== savedValue.trim() in both ChatMessage.tsx:1345 and ConversationMessage.tsx:455 (compare formatted-source to formatted-result, trimmed on both sides). Add an empty-content guard (reject, or confirm before persisting ""). Alternatively, seed the textarea with raw content and only format the user's actual keystrokes.


AI-investigated against v2.0.6; both guards read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2959 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The "did the user actually change anything?" check on an edit save compares the **transformed** edit value against the **untransformed** stored content. Because those two baselines differ, a save that the user intended as a no-op can still fire and rewrite the message: - With **typographic quotes** enabled, opening an edit and pressing Save without typing anything converts all the message's straight quotes to curly quotes in storage. A downstream regex/macro that matched straight quotes then silently stops matching. - A message with **trailing whitespace/newlines** gets that whitespace stripped on a no-op save (the saved value is trimmed, the baseline isn't). - Separately, clearing the textarea and saving persists a **blank** message. **How to reproduce (try it yourself)** Typographic quotes: 1. Settings → enable typographic quotes (default is "straight"). 2. Have a message whose stored content has straight quotes, e.g. `"hello"` (typical AI output). 3. Open edit, type nothing, press Save. **You'll see:** stored content becomes `“hello”` (curly). A regex/macro matching `"` no longer matches. **Expected:** a no-op save changes nothing. Whitespace / empty: - Open edit on a message with trailing newlines, change nothing, Save → the trailing whitespace is gone. - Open edit, delete all text, Save → an empty message is saved and renders blank. **Expected:** no-op preserves content; empty save is rejected (or confirmed). **Where it is** `packages/client/src/components/chat/ChatMessage.tsx` — the textarea is seeded with `formatTextQuotes(initialContent, quoteFormat)` (307) and `handleSave` re-runs `formatTextQuotes` (300), but the change guard compares against **raw** content: `if (content.trim() !== message.content)` (1345). Same shape in `packages/client/src/components/chat/ConversationMessage.tsx`: `val = formatTextQuotes(editValueRef.current.trim(), quoteFormat)` then `if (val !== editSourceContent)` (454-455), where `editSourceContent` is the raw, untrimmed source (426). The server (`chats.routes.ts:1651` → `updateMessageContent`) stores whatever it's given, with no empty/length check. `formatTextQuotes` is in `packages/shared/src/utils/quote-format.ts`. **What's happening** The textarea value is normalized (curly quotes, trimmed) while the no-op baseline is the raw stored content, so any quote-style or trailing-whitespace difference makes a no-op look like a change and persists the wholesale transform. There's also no guard against saving empty content. **Suggested fix** Compare like-for-like: gate the save on `formatTextQuotes(rawSource, quoteFormat).trim() !== savedValue.trim()` in both `ChatMessage.tsx:1345` and `ConversationMessage.tsx:455` (compare formatted-source to formatted-result, trimmed on both sides). Add an empty-content guard (reject, or confirm before persisting `""`). Alternatively, seed the textarea with raw content and only format the user's actual keystrokes. --- *AI-investigated against v2.0.6; both guards read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in staging: edit saves ignore empty content and compare against the formatted edit source so no-op saves no longer rewrite punctuation/whitespace. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4830956158 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in staging: edit saves ignore empty content and compare against the formatted edit source so no-op saves no longer rewrite punctuation/whitespace. Validated with pnpm check and pnpm regression:prompt.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1534
No description provided.