feat: remember last nickname + sanitize chat input

Remember last nickname: a new serde-default AppConfig.username field is
pre-filled into the launch-screen nickname field, and saved when a room is
joined or created (i.e. when the name is actually used), so it carries across
launches.

Sanitize chat: a pure sanitize_chat() drops control characters (ANSI escapes,
NUL, stray CR/LF/TAB), collapses whitespace runs to single spaces, trims, and
caps length (2000 chars). Applied to our outgoing text on submit AND to incoming
peer messages on receive — peer content is untrusted, so the sender's name and
text are both sanitized before display; empty-after-sanitize messages are
dropped. Unit tests for sanitize_chat (control/whitespace/unicode/empty + length
cap) and a config backward-compat assertion for username.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 23:02:08 -04:00
co-authored by Claude Opus 4.8
parent 5279a53400
commit b436b57f13
2 changed files with 66 additions and 3 deletions
+10
View File
@@ -44,6 +44,10 @@ fn default_volume() -> f32 {
1.0
}
fn default_username() -> String {
"Peer".to_string()
}
fn default_participants_width() -> f32 {
540.0
}
@@ -54,6 +58,9 @@ fn default_chat_height() -> f32 {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AppConfig {
/// Last nickname used to join/create a room; pre-filled on the launch screen.
#[serde(default = "default_username")]
pub username: String,
pub input_device: String,
pub output_device: String,
pub noise_gate_threshold: f32,
@@ -98,6 +105,7 @@ pub struct AppConfig {
impl Default for AppConfig {
fn default() -> Self {
Self {
username: default_username(),
input_device: "".to_string(),
output_device: "".to_string(),
noise_gate_threshold: 0.01,
@@ -176,6 +184,8 @@ mod tests {
// Configs predating the draggable dividers must load the default sizes.
assert_eq!(deserialized.participants_width, 540.0);
assert_eq!(deserialized.chat_height, 180.0);
// Configs predating the remembered username load the default nickname.
assert_eq!(deserialized.username, "Peer");
assert!(deserialized.custom_sound_self_join.is_none());
assert!(deserialized.custom_sound_peer_join.is_none());
assert!(deserialized.custom_sound_peer_leave.is_none());