1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

improved handling of unicode chat messages

This commit is contained in:
Robin Appelman 2020-02-09 16:40:34 +01:00
commit 90c5e6c7f9
4 changed files with 13 additions and 1 deletions

BIN
data/unicode-saytext.dem Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -183,7 +183,13 @@ impl BitRead<LittleEndian> for SayText2Message {
// cleanup color codes // cleanup color codes
let mut text = text.replace(char::from(1), "").replace(char::from(3), ""); let mut text = text.replace(char::from(1), "").replace(char::from(3), "");
while let Some(pos) = text.find(char::from(7)) { while let Some(pos) = text.chars().enumerate().find_map(|(index, c)| {
if c == char::from(7) {
Some(index)
} else {
None
}
}) {
text = text text = text
.chars() .chars()
.take(pos) .take(pos)

View file

@ -71,6 +71,11 @@ fn snapshot_test_malformed_cvar() {
snapshot_test("data/malformed_cvar.dem", "data/malformed_cvar.json"); snapshot_test("data/malformed_cvar.dem", "data/malformed_cvar.json");
} }
#[test]
fn snapshot_test_unicode_chat() {
snapshot_test("data/unicode-saytext.dem", "data/unicode-saytext.json");
}
#[test] #[test]
fn snapshot_test_player_in_update() { fn snapshot_test_player_in_update() {
snapshot_test("data/nousers.dem", "data/nousers.json"); snapshot_test("data/nousers.dem", "data/nousers.json");