Repository navigation
Normalize slotting JSON encoding on paste - #40
Conversation
Slotting JSON reaches the admin panel through the clipboard, and that is
where the Arma lobby export loses its encoding. The mod hands the OS raw
UTF-8 bytes as single-byte text, so Cyrillic role names arrive re-read as
Windows-1252 ("Командир" -> "Командир"), and the mod's own
workaround for that ships the names as \uXXXX escapes, which are correct
but unreadable in the textarea.
Handle both at the single point the text enters the app:
- repairWindows1252Mojibake() maps each character back to its CP1252 byte
and re-decodes as strict UTF-8. It bails out on anything that is not
that damage — text holding characters CP1252 cannot express, or bytes
that are not valid UTF-8 — so a correct paste is never touched.
- normalizeSlottingJsonText() repairs, then re-serializes valid JSON so
escapes render as the characters they stand for.
Wired to the slotting textarea's onPaste only; typing and hand-edits are
left alone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 46 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe change adds conservative Windows-1252 mojibake repair and JSON normalization utilities, tests their behavior, and applies normalization to pasted content in the admin slotting JSON textarea. ChangesSlotting clipboard normalization
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Clipboard
participant SlottingTextarea
participant normalizeSlottingJsonText
Clipboard->>SlottingTextarea: Paste text
SlottingTextarea->>normalizeSlottingJsonText: Normalize clipboard text
normalizeSlottingJsonText-->>SlottingTextarea: Return normalized text
SlottingTextarea->>SlottingTextarea: Replace selected range
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/features/games/domain/slottingText.ts`:
- Around line 65-92: Update the mojibake repair logic around the decoding flow
and its enclosing helper to avoid transforming ambiguous CP1252-representable
text such as “©”. Require an unambiguous repair signal or explicit operator
confirmation before returning a decoded value, preserve the existing no-op
behavior otherwise, and add a regression test covering JSON input with
{"role":"©"}.
In `@tests/features/games/domain/slottingText.unit.test.ts`:
- Around line 11-14: Update toLatin1Mojibake so it decodes the UTF-8 bytes using
a raw byte-to-character conversion that preserves ISO-8859-1 values 0x80–0x9F as
C1 controls, instead of TextDecoder('latin1')’s Windows-1252 mapping. Keep the
fixture’s intended UTF-8-to-Latin-1 mojibake behavior unchanged for other byte
values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a850d027-20f4-409c-bad5-cf70ec921511
📒 Files selected for processing (3)
src/features/games/domain/slottingText.tssrc/features/games/ui/AdminGameMissionPage.tsxtests/features/games/domain/slottingText.unit.test.ts
Review catch: "©" is byte-identical to the mojibake of "©", so the repair
rewrote text that was already correct — contradicting the no-op contract
the helper documents.
Require the decode to reveal a character beyond Latin-1 before accepting
it. Real damage here decodes to Cyrillic, and to Arabic or Ukrainian for
the site's other locales, none of which can be mistaken for intentional
Latin-1 text. Accent-only damage ("café") is no longer repaired, which is
the price of not corrupting slot data.
Also pin the latin-1 test fixture to an explicit byte-to-character
mapping: TextDecoder('latin1') handling of the 0x80-0x9F block has moved
between Node releases, so a version bump would silently change which
encoding that test covers.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Problem
Slotting JSON reaches the admin panel through the clipboard, and that is where the Arma lobby export loses its encoding. The mod hands the OS raw UTF-8 bytes as single-byte text, so Cyrillic role names arrive re-read as Windows-1252:
The mod's own workaround for that ships role names as
\uXXXXescapes — correct data, but unreadable in the textarea:Change
Handle both at the single point the text enters the app —
onPasteon the slotting JSON textarea.New
src/features/games/domain/slottingText.ts:repairWindows1252Mojibake()maps each character back to its CP1252 byte and re-decodes as strict UTF-8. It returnsnull— leaving the text untouched — for anything that is not that specific damage: text holding characters CP1252 cannot express (real Cyrillic, CJK, emoji) or a byte stream that is not valid UTF-8. That conservative bail is what makes it safe to run over every paste.normalizeSlottingJsonText()repairs, then re-serializes valid JSON so escapes render as the characters they stand for. A partial or hand-edited paste that is not valid JSON on its own is kept verbatim, with only the encoding repair applied.Paste anything — escaped, mangled, or already clean — and the field shows the same text the mission page will render. Typing and hand-edits are untouched; nothing runs on
onChange.Testing
tests/features/games/domain/slottingText.unit.test.ts, using mojibake strings captured from a real/slotexportpaste rather than generated ones (Node'sTextDecoder('windows-1252')decodes the0x80–0x9Fblock as latin-1, so it does not reproduce what Windows actually puts on the clipboard). Both flavours of the damage are covered.tsc --noEmitclean,eslint0 errors on the touched files.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes