hle(xgameui): treat maxTextLength=0 as default 1024-character limit #295

Open
Caasares wants to merge 1 commit from upstream-pr/295 into main
Caasares commented 2026-11-24 23:21:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Caasares on 2026-11-24T23:21:01Z.


Fixes #248

Root Cause

Per GDK documentation for XGameUiShowTextEntryAsync, maxTextLength == 0 specifies the default limit of 1024 characters. Previously, crates/victory-hle/src/modules/xgameui.rs:

  • Passed max_length = 0 straight into ask / dialog::ask (EM_LIMITTEXT with wParam = 0 sets the edit control's maximum capacity rather than 1024).
  • Treated 0 as "no limit" inside limit(typed, max), returning all characters (e.g., all 1025 characters for a 1025-character input).

Fix

  • Added DEFAULT_MAX_TEXT_LENGTH = 1024 and effective_max_length(max) in crates/victory-hle/src/modules/xgameui.rs to normalize 0 to 1024.
  • Normalized max_length at entry in text_entry_async before calling ask and limit, updated limit to cap at effective_max_length(max) characters, and normalized dialog::ask / dialog::limit_text_wparam for EM_LIMITTEXT.
  • Added unit tests (max_length_zero_applies_1024_default and explicit_positive_limit_and_utf8_boundaries) covering maxTextLength = 0 on 1025-character ASCII and multi-byte UTF-8 inputs, explicit positive limits (16), shorter pass-through inputs, dialog::limit_text_wparam, and NUL-terminated buffer sizing.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • cargo test --workspace --locked: 498 passed, 0 failed, 7 ignored (including victory-hle 97 passed, 3 modules::xgameui::tests::*, and xtask::policy::tests::repository_passes_policy)
  • cargo fmt --all -- --check: fails only on pre-existing unformatted lines outside this diff (also present on pre-existing lines in xgameui.rs); all added/modified lines conform to rustfmt.toml.

AI-assisted contribution. Contains no game files, code, or assets.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593413157 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/295). Originally posted by [Caasares](https://github.com/Caasares) on 2026-11-24T23:21:01Z. --- Fixes #248 ## Root Cause Per GDK documentation for `XGameUiShowTextEntryAsync`, `maxTextLength == 0` specifies the default limit of `1024` characters. Previously, `crates/victory-hle/src/modules/xgameui.rs`: - Passed `max_length = 0` straight into `ask` / `dialog::ask` (`EM_LIMITTEXT` with `wParam = 0` sets the edit control's maximum capacity rather than `1024`). - Treated `0` as "no limit" inside `limit(typed, max)`, returning all characters (e.g., all 1025 characters for a 1025-character input). ## Fix - Added `DEFAULT_MAX_TEXT_LENGTH = 1024` and `effective_max_length(max)` in `crates/victory-hle/src/modules/xgameui.rs` to normalize `0` to `1024`. - Normalized `max_length` at entry in `text_entry_async` before calling `ask` and `limit`, updated `limit` to cap at `effective_max_length(max)` characters, and normalized `dialog::ask` / `dialog::limit_text_wparam` for `EM_LIMITTEXT`. - Added unit tests (`max_length_zero_applies_1024_default` and `explicit_positive_limit_and_utf8_boundaries`) covering `maxTextLength = 0` on 1025-character ASCII and multi-byte UTF-8 inputs, explicit positive limits (`16`), shorter pass-through inputs, `dialog::limit_text_wparam`, and NUL-terminated buffer sizing. ## Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `cargo test --workspace --locked`: 498 passed, 0 failed, 7 ignored (including `victory-hle` 97 passed, 3 `modules::xgameui::tests::*`, and `xtask::policy::tests::repository_passes_policy`) - `cargo fmt --all -- --check`: fails only on pre-existing unformatted lines outside this diff (also present on pre-existing lines in `xgameui.rs`); all added/modified lines conform to `rustfmt.toml`. *AI-assisted contribution. Contains no game files, code, or assets.*
kaayzouee commented 2026-11-25 02:10:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:12:49Z.


Duplicate of #291?

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149319570 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/295#issuecomment-7149319570). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:12:49Z. --- Duplicate of #291?
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/295:upstream-pr/295'
git switch 'upstream-pr/295'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/295'
git switch 'upstream-pr/295'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/295'
git switch 'upstream-pr/295'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/295'
git switch 'main'
git merge --squash 'upstream-pr/295'
git switch 'main'
git merge --ff-only 'upstream-pr/295'
git switch 'main'
git merge 'upstream-pr/295'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
fxceless/victory-fork!295
No description provided.