Browse Source

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

pbs
jake 5 years ago
parent
commit
3b9f6dc087
  1. 4
      src/login/character.rs
  2. 2
      src/ship/room.rs

4
src/login/character.rs

@ -534,7 +534,7 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
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;
@ -726,7 +726,7 @@ mod test {
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());
}
}

2
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],
})

Loading…
Cancel
Save