From 3b9f6dc087cb7b6297358153d40e7bfb9c5649db Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 25 Jan 2020 18:02:17 -0800 Subject: [PATCH] trim nulls off end of utf16 converted strings (and fix a test) --- src/login/character.rs | 6 +++--- src/ship/room.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/login/character.rs b/src/login/character.rs index 63285ef..58b7e33 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -534,7 +534,7 @@ impl ServerState for CharacterServerState { fn new_character_from_preview(character: &mut Character, preview: &CharacterPreview) { character.slot = preview.slot; - character.name = String::from_utf16_lossy(&preview.character.name); + character.name = String::from_utf16_lossy(&preview.character.name).trim_matches(char::from(0)).into(); character.section_id = preview.character.section_id.into(); character.char_class = preview.character.ch_class.into(); character.appearance.costume = preview.character.costume; @@ -724,9 +724,9 @@ mod test { play_time: 0, } })).unwrap().collect::>(); assert!(send.len() == 2); - + let chars = TestData.get_characters_by_user(&fake_user.user.unwrap()); - assert!(chars[1].unwrap().character.name == [9, 69, 116, 101, 115, 116, 32, 110, 97, 109, 101, 0, 0, 0, 0, 0]); + assert!(chars[1].as_ref().unwrap().name == "\tEtest name"); assert!(chars[0].is_none()); } } diff --git a/src/ship/room.rs b/src/ship/room.rs index d67c963..ca53f19 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -140,7 +140,7 @@ impl RoomState { Ok(RoomState { mode: room_mode, - name: String::from_utf16_lossy(&create_room.name), + name: String::from_utf16_lossy(&create_room.name).trim_matches(char::from(0)).into(), password: create_room.password, maps: [0; 0x20], })