Skip to content

Normalize slotting JSON encoding on paste - #40

Merged
Jumbo13th merged 2 commits into
mainfrom
fix/slotting-json-paste-encoding
Jul 25, 2026
Merged

Jumbo13th merged 2 commits into
mainfrom
fix/slotting-json-paste-encoding

Conversation

@Jumbo13th

@Jumbo13th Jumbo13th commented Jul 25, 2026 •

Copy link
Copy Markdown
Owner

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:

"role": "Командир взвода"     // should be "Командир взвода"

The mod's own workaround for that ships role names as \uXXXX escapes — correct data, but unreadable in the textarea:

"role": "Командир взвода"

Change

Handle both at the single point the text enters the app — onPaste on 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 returns null — 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

  • 10 new unit tests in tests/features/games/domain/slottingText.unit.test.ts, using mojibake strings captured from a real /slotexport paste rather than generated ones (Node's TextDecoder('windows-1252') decodes the 0x80–0x9F block as latin-1, so it does not reproduce what Windows actually puts on the clipboard). Both flavours of the damage are covered.
  • Full suite: 421 tests / 62 files passing.
  • tsc --noEmit clean, eslint 0 errors on the touched files.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved slotting JSON paste handling in the admin game editor.
    • Automatically repairs common Windows-1252 encoding issues from clipboard content.
    • Reformats valid slotting JSON with consistent indentation while preserving partial or invalid text.
  • Bug Fixes

    • Prevents pasted Cyrillic and other special characters from appearing corrupted.
    • Preserves only the selected text range when normalized content is pasted.

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>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Jumbo13th, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 60d1d28a-83d3-4112-b3c7-e0881ac39ec5

📥 Commits

Reviewing files that changed from the base of the PR and between 3e45b31 and 2d88ee4.

📒 Files selected for processing (2)
  • src/features/games/domain/slottingText.ts
  • tests/features/games/domain/slottingText.unit.test.ts

Walkthrough

The 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.

Changes

Slotting clipboard normalization

Layer / File(s) Summary
Encoding repair and JSON normalization
src/features/games/domain/slottingText.ts, tests/features/games/domain/slottingText.unit.test.ts
Adds Windows-1252 mojibake detection and repair, JSON pretty-print normalization, result flags, and unit coverage for repaired, clean, invalid, and fragment inputs.
Admin editor paste integration
src/features/games/ui/AdminGameMissionPage.tsx
Intercepts slotting textarea paste events, normalizes clipboard text, and replaces the current selection when the normalized value differs.

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
Loading

Poem

A rabbit nips the pasted bytes,
And mends their crooked flight,
JSON hops in tidy rows,
Two spaces make it right.
The textarea twitches, clean and bright—
“Thump,” says Bun, “what a delight!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: normalizing slotting JSON encoding during paste.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/slotting-json-paste-encoding

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7441f and 3e45b31.

📒 Files selected for processing (3)
  • src/features/games/domain/slottingText.ts
  • src/features/games/ui/AdminGameMissionPage.tsx
  • tests/features/games/domain/slottingText.unit.test.ts

Comment thread src/features/games/domain/slottingText.ts
Comment thread tests/features/games/domain/slottingText.unit.test.ts Outdated
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>
@Jumbo13th
Jumbo13th merged commit c8ba79c into main Jul 25, 2026
2 checks passed
@Jumbo13th
Jumbo13th deleted the fix/slotting-json-paste-encoding branch July 25, 2026 09:00
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