[PR #5312] [MERGED] Chat messages are normalized the way ChatScreen.handleChatInput does (trim, collapsed spaces, 256 UTF-16 units) #6204

Closed
opened 2026-11-03 06:15:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5312
Author: @sirrayi
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/chat-normalize-message


📝 Commits (2)

  • f630fd4 ChatScreen.normalizeChatMessage: the message a chat screen sends
  • 2b9d830 tooling(port-map): ChatScreen.send's two rows

📊 Changes

4 files changed (+96 additions, -9 deletions)

View changed files

📝 crates/horizon-client-render/src/chat.rs (+47 -0)
📝 crates/horizon-client-render/src/chat_tests.rs (+35 -0)
📝 crates/horizon-client/src/game/chat.rs (+12 -9)
📝 tools/port_map/client2-013.tsv (+2 -0)

📄 Description

🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally.

Refs #3518 (its chat rows; not a Fixes: the two signing rows there are #4375 to #4377's, and ChatListener.handleChatMessageError merged today in #5149). This is the one part of the chat send path no open pull request covers.

What and why

The chat screen sent the box text as typed. Vanilla does not: ChatScreen.handleChatInput first runs the message through ChatScreen.normalizeChatMessage, which is String.trim, then StringUtils.normalizeSpace (one space for every run of whitespace), then StringUtil.trimChatMessage (the first 256 UTF-16 code units), and only then sends it as a chat line or as a command. Horizon did none of the three, so on main today:

  • A message too long for the packet went out and the server refused it. send_chat cut the message with chars().take(256), so 256 emoji passed as 512 UTF-16 code units, while ServerboundChatPacket's stringUtf8(256) counts code units and vanilla keeps 128 of them. The chat box had accepted text the server then decodes as too long.
  • Runs of spaces reached other players, and a line of nothing but spaces was sent; vanilla sends nothing for it and does not put it in the history.
  • The history remembered what was typed, not what went out, because addRecentChat gets the normalized message in vanilla.

The change

  • horizon-client-render/src/chat.rs: normalize_chat_message (ChatScreen.normalizeChatMessage), normalize_space (StringUtils.normalizeSpace) and truncate_utf16 (StringUtil.truncateStringIfNecessary(s, 256, false)). java_whitespace is reused from ui.rs, so the rules stay Java's: U+00A0 is not whitespace and stays (leading ones included, since String.trim only strips code points up to U+0020), while U+3000 and Java's U+001C..U+001F separators collapse to a space.
  • game/chat.rs: Game::handle_chat_input (ChatScreen.handleChatInput) normalizes first and returns on an empty message before the history, which is where vanilla does both. That covers the chat box, a restored draft and horizon-ctl's chat, and keeps send_chat's own trim for the callers that do not go through the screen.
  • Port map: the two ChatScreen rows that had no verdict at all (client2-013.tsv).

A cut between the halves of a surrogate pair keeps the character below it. Vanilla's substring(0, 256) may leave half a pair, which a Java String holds; a Rust String cannot, so a 129th emoji is dropped whole. That is the one place this is not byte-identical, and it is the case where vanilla would send a replacement character.

Release notes

Fixed

  • Chat messages are sent as vanilla sends them: runs of spaces become one, a message of nothing but spaces sends nothing and is not added to the history, and a long message (emoji especially) is cut to the 256 UTF-16 code units a server accepts instead of being refused after the box took it.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

ChatScreen.normalizeChatMessage, ChatScreen.handleChatInput and ChatScreen.init (the 256 limit), StringUtil.trimChatMessage / truncateStringIfNecessary, StringUtils.normalizeSpace, Character.isWhitespace, ServerboundChatPacket.STREAM_CODEC (stringUtf8(256)), ChatComponent.addRecentChat. Read from the 26.3 jar's bytecode (javap), since the decompiled sources are not on this machine.

No harness: there is no vanilla oracle for String.trim/normalizeSpace text handling to compare against, and the three rules are pinned in unit tests instead (chat_tests.rs): trimming and collapsing (including U+00A0, U+3000 and U+001C), the 256-code-unit cut at 256 ASCII, 300 ASCII and 129 emoji, and a cut that would split a surrogate pair.

Other projects' code

none

Self-check

**pr_ready** (`tools/pr_ready.py --quick` on MacBookPro, against origin/main at 3b1e813d9, 3 min 52 s)

| Check | Result |
| --- | --- |
| Scope | ✅ 4 files, +96 −9 |
| Cargo.lock | ✅ unchanged |
| Public tree | ✅ |
| Python tests | ❌ 477 run, FAILED (errors=14, skipped=1) (1 min 2 s) |
| rustfmt | ✅ (10 s) |
| clippy | ❌ failed (31 s) |
| tests: horizon-client, horizon-client-render | ✅ 2171 passed (1 min 58 s) |
| doc tests | ✅ 0 passed (11 s) |
| content root tests | ➖ content root untouched |
| tokens.css up to date | ➖ theme untouched |
| launcher rustfmt | ➖ launcher untouched |
| launcher clippy | ➖ launcher untouched |
| launcher tests | ➖ launcher untouched |
| Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses |

Both ❌ are on main, not here:

  • clippy is one warning, unreachable pattern at crates/horizon-client/src/lan/hub.rs:2810 (a second S::Attack arm), which pr_ready turns into an error; it is on origin/main too and this branch does not touch that file. cargo clippy -p horizon-client --lib on this branch reports nothing else.
  • Python tests are 14 errors in test_lab, the parity-runner tests and test_roadmap, which need the launcher install and the prepared vanilla data. A pristine origin/main checkout on this machine fails the same way (python3 -m unittest tests.test_lab → 7 errors).

Screenshots

None: producing them needs the prepared resources (.local/), which this machine does not have. The visible difference is the message on the wire and the history entry; the tests pin both. Happy to add them if you want them before merging.

🤖 Generated with DeepSeek Harness (deepseek-v4.1-flash) on sirrayi's account


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5312 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/chat-normalize-message` --- ### 📝 Commits (2) - [`f630fd4`](https://github.com/horizon-rust/horizon/commit/f630fd43bbd30a2c78254a0ed94493d37f44c5db) ChatScreen.normalizeChatMessage: the message a chat screen sends - [`2b9d830`](https://github.com/horizon-rust/horizon/commit/2b9d830a3f6b3804334dda635634bdc80df87f8b) tooling(port-map): ChatScreen.send's two rows ### 📊 Changes **4 files changed** (+96 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/chat.rs` (+47 -0) 📝 `crates/horizon-client-render/src/chat_tests.rs` (+35 -0) 📝 `crates/horizon-client/src/game/chat.rs` (+12 -9) 📝 `tools/port_map/client2-013.tsv` (+2 -0) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally. Refs #3518 (its chat rows; not a `Fixes`: the two signing rows there are #4375 to #4377's, and `ChatListener.handleChatMessageError` merged today in #5149). This is the one part of the chat send path no open pull request covers. ## What and why The chat screen sent the box text as typed. Vanilla does not: `ChatScreen.handleChatInput` first runs the message through `ChatScreen.normalizeChatMessage`, which is `String.trim`, then `StringUtils.normalizeSpace` (one space for every run of whitespace), then `StringUtil.trimChatMessage` (the first 256 UTF-16 code units), and only then sends it as a chat line or as a command. Horizon did none of the three, so on main today: - **A message too long for the packet went out and the server refused it.** `send_chat` cut the message with `chars().take(256)`, so 256 emoji passed as 512 UTF-16 code units, while `ServerboundChatPacket`'s `stringUtf8(256)` counts code units and vanilla keeps 128 of them. The chat box had accepted text the server then decodes as too long. - **Runs of spaces reached other players**, and a line of nothing but spaces was sent; vanilla sends nothing for it and does not put it in the history. - **The history remembered what was typed, not what went out**, because `addRecentChat` gets the normalized message in vanilla. ## The change - `horizon-client-render/src/chat.rs`: `normalize_chat_message` (`ChatScreen.normalizeChatMessage`), `normalize_space` (`StringUtils.normalizeSpace`) and `truncate_utf16` (`StringUtil.truncateStringIfNecessary(s, 256, false)`). `java_whitespace` is reused from `ui.rs`, so the rules stay Java's: U+00A0 is not whitespace and stays (leading ones included, since `String.trim` only strips code points up to U+0020), while U+3000 and Java's U+001C..U+001F separators collapse to a space. - `game/chat.rs`: `Game::handle_chat_input` (`ChatScreen.handleChatInput`) normalizes first and returns on an empty message before the history, which is where vanilla does both. That covers the chat box, a restored draft and `horizon-ctl`'s `chat`, and keeps `send_chat`'s own `trim` for the callers that do not go through the screen. - Port map: the two `ChatScreen` rows that had no verdict at all (`client2-013.tsv`). A cut between the halves of a surrogate pair keeps the character below it. Vanilla's `substring(0, 256)` may leave half a pair, which a Java `String` holds; a Rust `String` cannot, so a 129th emoji is dropped whole. That is the one place this is not byte-identical, and it is the case where vanilla would send a replacement character. ## Release notes **Fixed** - Chat messages are sent as vanilla sends them: runs of spaces become one, a message of nothing but spaces sends nothing and is not added to the history, and a long message (emoji especially) is cut to the 256 UTF-16 code units a server accepts instead of being refused after the box took it. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `ChatScreen.normalizeChatMessage`, `ChatScreen.handleChatInput` and `ChatScreen.init` (the 256 limit), `StringUtil.trimChatMessage` / `truncateStringIfNecessary`, `StringUtils.normalizeSpace`, `Character.isWhitespace`, `ServerboundChatPacket.STREAM_CODEC` (`stringUtf8(256)`), `ChatComponent.addRecentChat`. Read from the 26.3 jar's bytecode (`javap`), since the decompiled sources are not on this machine. No harness: there is no vanilla oracle for `String.trim`/`normalizeSpace` text handling to compare against, and the three rules are pinned in unit tests instead (`chat_tests.rs`): trimming and collapsing (including U+00A0, U+3000 and U+001C), the 256-code-unit cut at 256 ASCII, 300 ASCII and 129 emoji, and a cut that would split a surrogate pair. ## Other projects' code none ## Self-check ``` **pr_ready** (`tools/pr_ready.py --quick` on MacBookPro, against origin/main at 3b1e813d9, 3 min 52 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +96 −9 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 477 run, FAILED (errors=14, skipped=1) (1 min 2 s) | | rustfmt | ✅ (10 s) | | clippy | ❌ failed (31 s) | | tests: horizon-client, horizon-client-render | ✅ 2171 passed (1 min 58 s) | | doc tests | ✅ 0 passed (11 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | ``` Both ❌ are on main, not here: - **clippy** is one warning, `unreachable pattern` at `crates/horizon-client/src/lan/hub.rs:2810` (a second `S::Attack` arm), which `pr_ready` turns into an error; it is on `origin/main` too and this branch does not touch that file. `cargo clippy -p horizon-client --lib` on this branch reports nothing else. - **Python tests** are 14 errors in `test_lab`, the parity-runner tests and `test_roadmap`, which need the launcher install and the prepared vanilla data. A pristine `origin/main` checkout on this machine fails the same way (`python3 -m unittest tests.test_lab` → 7 errors). ## Screenshots None: producing them needs the prepared resources (`.local/`), which this machine does not have. The visible difference is the message on the wire and the history entry; the tests pin both. Happy to add them if you want them before merging. 🤖 Generated with [DeepSeek Harness](https://github.com/deepseek) (deepseek-v4.1-flash) on sirrayi's account --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:15:51 +07:00
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
horizon-rust/horizon#6204
No description provided.