fix another edge case in FormattedText::from_nbt_tag that happens with viaversion

This commit is contained in:
mat 2024-05-22 10:28:43 +00:00
parent 729d211406
commit 73bcc6639b
2 changed files with 21 additions and 0 deletions

View file

@ -420,6 +420,8 @@ impl simdnbt::FromNbtTag for FormattedText {
// keybind text components aren't yet supported
trace!("keybind text components aren't yet supported");
return None;
} else if let Some(tag) = compound.get("") {
return FormattedText::from_nbt_tag(tag);
} else {
let _nbt = compound.get("nbt")?;
let _separator = FormattedText::parse_separator_nbt(compound)?;

View file

@ -7,3 +7,22 @@ pub struct ClientboundTabListPacket {
pub header: FormattedText,
pub footer: FormattedText,
}
#[cfg(test)]
mod tests {
use std::io::Cursor;
use azalea_buf::McBufReadable;
use super::*;
#[test]
fn test_packet_from_viaversion() {
#[rustfmt::skip]
let mut bytes = Cursor::new(&[
10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 3, 1, 0, 4, 98, 111, 108, 100, 1, 8, 0, 4, 116, 101, 120, 116, 0, 16, 50, 66, 85, 73, 76, 68, 69, 82, 83, 50, 84, 79, 79, 76, 83, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 114, 97, 121, 0, 8, 0, 0, 0, 1, 10, 0, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 27, 80, 101, 110, 100, 105, 110, 103, 32, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 32, 116, 111, 32, 50, 98, 50, 116, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0, 10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 1, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 72, 84, 104, 105, 115, 32, 97, 99, 99, 111, 117, 110, 116, 32, 104, 97, 115, 32, 112, 114, 105, 111, 114, 105, 116, 121, 32, 115, 116, 97, 116, 117, 115, 32, 97, 110, 100, 32, 119, 105, 108, 108, 32, 98, 101, 32, 112, 108, 97, 99, 101, 100, 32, 105, 110, 32, 97, 32, 115, 104, 111, 114, 116, 101, 114, 32, 113, 117, 101, 117, 101, 46, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0
][..]);
let _packet = ClientboundTabListPacket::read_from(&mut bytes).unwrap();
assert!(bytes.get_ref()[bytes.position() as usize..].is_empty());
}
}