Skip to content

fix: normalize smart punctuation (em dash → --) in chat input#242

Merged
StephaneDelcroix merged 2 commits intomainfrom
fix/while-typing-double---like--in-the-comma-20260227-1846
Feb 28, 2026
Merged

fix: normalize smart punctuation (em dash → --) in chat input#242
StephaneDelcroix merged 2 commits intomainfrom
fix/while-typing-double---like--in-the-comma-20260227-1846

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Collaborator

Problem

On Mac Catalyst, WebKit's smart text substitution converts -- to (em dash) in textarea inputs. This breaks CLI commands that use double-dash flags (e.g., git log --oneline), especially in ! mode.

Fix

Three-layer defense:

  1. HTML prevention: Added autocorrect="off" to all command-input textareas (ExpandedSessionView, Dashboard, SessionSidebar) to prevent WebKit smart substitution at the source.

  2. JS normalization: Added normalizeSmartPunctuation() in getElementValue() (index.html) to convert em dashes, en dashes, and smart quotes back to ASCII before values reach C# code. This catches pasted text and edge cases.

  3. C# safety net: Added SmartPunctuationNormalizer utility applied at the SendPromptAsync entry point as a final defense for programmatic callers.

Tests

Added 10 unit tests covering:

  • Em dash → -- conversion
  • En dash → - conversion
  • Smart single/double quotes → ASCII
  • Mixed smart punctuation normalization
  • Null/empty/plain ASCII passthrough
  • CLI flag and ```` mode scenarios

All 1555 tests pass. Mac Catalyst build succeeds.

StephaneDelcroix and others added 2 commits February 28, 2026 10:18
macOS/WebKit automatically converts '--' to '—' (em dash) in textareas,
breaking CLI commands with flag syntax (e.g., 'git log --oneline').

Three-layer fix:
1. HTML: Add autocorrect='off' to all command-input textareas to prevent
   WebKit smart text substitution at the source.
2. JS: Normalize smart punctuation (em dash, en dash, smart quotes) back
   to ASCII in getElementValue() before values reach C# code.
3. C#: SmartPunctuationNormalizer applied in SendPromptAsync as a final
   safety net for programmatic callers and pasted text.

Fixes: typing '--' in ! mode produces '—' instead of '--'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove JS normalization from getElementValue() to avoid silently
rewriting session/group/preset names. The C# layer in SendPromptAsync
is the correctly-scoped safety net.

Also fix Normalize() to accept string? and return string.Empty for
null input instead of null.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StephaneDelcroix StephaneDelcroix force-pushed the fix/while-typing-double---like--in-the-comma-20260227-1846 branch from eaf4000 to a809143 Compare February 28, 2026 09:20
@StephaneDelcroix
Copy link
Copy Markdown
Collaborator Author

✅ Multi-Model Review: Ready to Merge

Initial 5-model review found 2 issues. Both fixed in commit a809143:

🟡 getElementValue() normalized ALL inputs (5/5 models) — JS normalization in the generic getElementValue() helper silently rewrote session names, group names, and preset names. Fix: removed JS normalization; the C# layer in SendPromptAsync is the correctly-scoped defense.

🟡 Normalize() return type mismatch (4/5 models) — Method declared string but returned null for null input. Fix: changed to Normalize(string? text) returning string.Empty for null.

Post-fix re-review (5 models): Both issues confirmed fixed. All 10 normalizer tests pass. All prompt paths verified to converge on SendPromptAsync where C# normalization runs.

@StephaneDelcroix StephaneDelcroix merged commit 41b3fe6 into main Feb 28, 2026
@StephaneDelcroix StephaneDelcroix deleted the fix/while-typing-double---like--in-the-comma-20260227-1846 branch February 28, 2026 09:44
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