fix(server): use char count (not byte length) for display_name limit
The leaderboard opt-in handler was calling `.len()` on the display name, which returns byte count. Multi-byte Unicode characters (emoji, CJK, etc.) would be rejected well before the 32-character visual limit and with a misleading error message. Switched to `.chars().count()` to enforce the limit in terms of Unicode scalar values as the error message advertises. test(core): add boundary tests for 7 uncovered achievement conditions test(server): add display_name validation integration tests (empty, too-long ASCII, 32-emoji succeeds, 33-emoji rejected) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -119,7 +119,7 @@ pub async fn opt_in(
|
||||
if display_name.is_empty() {
|
||||
return Err(AppError::BadRequest("display_name must not be empty".into()));
|
||||
}
|
||||
if display_name.len() > DISPLAY_NAME_MAX {
|
||||
if display_name.chars().count() > DISPLAY_NAME_MAX {
|
||||
return Err(AppError::BadRequest(format!(
|
||||
"display_name must be at most {DISPLAY_NAME_MAX} characters"
|
||||
)));
|
||||
|
||||
Reference in New Issue
Block a user