Conversation
…uncate_to_chars` utility function for multi byte chars
- Added `emval` crate for email validation and normalization. - Introduced `normalize_email` utility function to standardize email addresses. - Implemented `validate_account_name` function to ensure usernames meet criteria. - Updated account creation logic to validate email and username before proceeding. - Added minimum name length configuration in `Config.toml` and updated character name validation to use configurable limits. - Enhanced character creation logic to validate character names based on new rules.
- Replaced `emval` dependency with `regex` for email validation. - Modified `normalize_email` function to use a regex for validating email format and return a more descriptive error using `anyhow`. - Updated SQL query parameters in `account.rs` to convert `username` to a `String` to avoid type mismatches.
There was a problem hiding this comment.
Pull request overview
This PR focuses on preventing crashes and improving robustness by tightening input validation, making UTF-8 string operations safe, improving error propagation in map-leave flows, simplifying save commands, and updating dependencies/config.
Changes:
- Added/centralized validation & normalization for account/character-related inputs (including new reply codes and config-driven min name length).
- Fixed several UTF-8/multibyte string handling paths (safe truncation/capitalization/info-box text capping) and added targeted unit tests.
- Refactored save + map leave behavior (async saves with batching; map leave now returns
Result) and updated dependencies.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/world/world/save.rs | Removes sync save and batches async map saves to reduce concurrent load. |
| src/world/world.rs | Routes Command::Save through async save. |
| src/utils/validate_character_name.rs | Updates character name validation to use config-driven bounds. |
| src/utils/validate_account_name.rs | Adds account name validation helper. |
| src/utils/truncate_to_chars.rs | Adds safe character-count truncation utility with tests. |
| src/utils/normalize_email.rs | Adds email normalization/validation helper. |
| src/utils/mod.rs | Exposes new utility modules (truncate/email/account-name validation). |
| src/utils/capitalize.rs | Fixes multibyte-safe capitalization and adds a test. |
| src/settings.rs | Adds character.min_name_length to settings struct. |
| src/player/player/handlers/warp.rs | Handles map leave errors instead of assuming success. |
| src/player/player/handlers/marriage.rs | Normalizes/validates character names before marriage operations. |
| src/player/player/handlers/item.rs | Enforces title length using Unicode character count. |
| src/player/player/handlers/character.rs | Validates character name and sends NotApproved reply on invalid input. |
| src/player/player/handlers/account.rs | Normalizes/validates usernames and emails; uses NotApproved reply code. |
| src/player/player/die.rs | Handles map leave errors to avoid panics/unwrapping failures. |
| src/player/player/close.rs | Updates close flow to handle leave() returning Result. |
| src/player/player/arena_die.rs | Handles map leave errors to avoid panics/unwrapping failures. |
| src/player/packet_bus.rs | Drops invalid too-short websocket packets early. |
| src/map/map_handle.rs | Changes leave() to return anyhow::Result<Character> and removes sync save wrapper. |
| src/map/map/utils/show_info_box.rs | Refactors text capping to be UTF-8 safe; adds a regression test. |
| src/map/map/character/set_character_property.rs | Validates/normalizes fiance/partner fields; Unicode-safe title length check. |
| src/map/map/board/create_board_post.rs | Uses character-aware truncation for subject/body. |
| src/map/map.rs | Removes redundant Command::Save handling in favor of async variant. |
| src/map/command.rs | Removes Save command variant (keeps SaveAsync). |
| config/Config.toml | Adds character.min_name_length configuration. |
| Cargo.toml | Bumps crate version and updates/adds dependencies (incl. regex). |
| Cargo.lock | Updates lockfile to match dependency changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 27 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 43 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request introduces several important improvements and fixes across the codebase, focusing on input validation, UTF-8 string handling, dependency updates, and error handling. The most notable changes are enhanced validation for account and character names, improved handling of multibyte strings, removal of a redundant save command, and updates to dependencies for better compatibility and security.
Input validation and normalization:
src/player/player/handlers/account.rs) [1] [2] [3] [4] [5] [6] [7].fiance,partner) and enforced character title length usingchars().count()for proper Unicode support (src/map/map/character/set_character_property.rs) [1] [2].UTF-8/multibyte string handling:
truncate_to_charsutility (src/map/map/board/create_board_post.rs) [1] [2].text_capto properly handle multibyte strings and prevent panics, and added a test to verify correct behavior (src/map/map/utils/show_info_box.rs) [1] [2].Error handling and code cleanup:
Result, propagating errors up and handling them gracefully in player logic (src/map/map_handle.rs,src/player/player/arena_die.rs,src/player/player/close.rs,src/player/player/die.rs) [1] [2] [3] [4].Savecommand in favor of the async variant, simplifying the command interface (src/map/command.rs,src/map/map.rs,src/map/map_handle.rs) [1] [2] [3].Dependency and configuration updates:
tokio-tungstenite,rusqlite,regex) to newer versions and bumped the crate version to1.16.0(Cargo.toml) [1] [2].min_name_lengthto character configuration for stricter name validation (config/Config.toml).Protocol and packet handling:
src/player/player/handlers/account.rs,src/player/player/handlers/character.rs) [1] [2].src/player/packet_bus.rs).