trim nulls off end of utf16 converted strings (and fix a test)

This commit is contained in:
jake 2020-01-25 18:02:17 -08:00
parent 28a30cb06f
commit 3b9f6dc087
2 changed files with 4 additions and 4 deletions

View File

@ -534,7 +534,7 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
fn new_character_from_preview(character: &mut Character, preview: &CharacterPreview) { fn new_character_from_preview(character: &mut Character, preview: &CharacterPreview) {
character.slot = preview.slot; 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.section_id = preview.character.section_id.into();
character.char_class = preview.character.ch_class.into(); character.char_class = preview.character.ch_class.into();
character.appearance.costume = preview.character.costume; character.appearance.costume = preview.character.costume;
@ -726,7 +726,7 @@ mod test {
assert!(send.len() == 2); assert!(send.len() == 2);
let chars = TestData.get_characters_by_user(&fake_user.user.unwrap()); 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()); assert!(chars[0].is_none());
} }
} }

View File

@ -140,7 +140,7 @@ impl RoomState {
Ok(RoomState { Ok(RoomState {
mode: room_mode, 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, password: create_room.password,
maps: [0; 0x20], maps: [0; 0x20],
}) })