From 7d20eda05adc55ad9d34305f5e71765cdb5830bd Mon Sep 17 00:00:00 2001 From: TicClick Date: Tue, 20 Feb 2024 13:53:49 +0100 Subject: [PATCH] Minor bugfixes for channel link parsing and chat tab state handling (#97) --- Cargo.lock | 4 ++-- crates/steel_core/Cargo.lock | 2 +- crates/steel_core/Cargo.toml | 2 +- crates/steel_core/src/chat/links.rs | 13 ++++++++----- src/gui/mod.rs | 4 ++-- src/gui/window.rs | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 203da78..b4db21d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3297,7 +3297,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "0.7.4" +version = "0.7.5" dependencies = [ "chrono", "eframe", @@ -3330,7 +3330,7 @@ dependencies = [ [[package]] name = "steel_core" -version = "0.1.4" +version = "0.1.5" dependencies = [ "chrono", "ecolor", diff --git a/crates/steel_core/Cargo.lock b/crates/steel_core/Cargo.lock index dcdf9c0..4ed42ef 100644 --- a/crates/steel_core/Cargo.lock +++ b/crates/steel_core/Cargo.lock @@ -740,7 +740,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "steel_core" -version = "0.1.4" +version = "0.1.5" dependencies = [ "chrono", "ecolor", diff --git a/crates/steel_core/Cargo.toml b/crates/steel_core/Cargo.toml index 20ae81d..ad61908 100644 --- a/crates/steel_core/Cargo.toml +++ b/crates/steel_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "steel_core" -version = "0.1.4" +version = "0.1.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/steel_core/src/chat/links.rs b/crates/steel_core/src/chat/links.rs index 73e34fc..de140e6 100644 --- a/crates/steel_core/src/chat/links.rs +++ b/crates/steel_core/src/chat/links.rs @@ -221,13 +221,16 @@ impl Message { // Channel name. if i < bs.len() && bs[i] == b'#' { i += 1; - while i < bs.len() && b'a' <= bs[i] && bs[i] <= b'z' { + while i < bs.len() && ((b'a' <= bs[i] && bs[i] <= b'z') || bs[i] == b'_') { i += 1; } - links.push(LinkLocation::Raw { - pos: (start, i), - protocol: LinkType::Channel, - }); + // '#' is an invalid channel name -- skip it. + if i > start + 1 { + links.push(LinkLocation::Raw { + pos: (start, i), + protocol: LinkType::Channel, + }); + } continue; } diff --git a/src/gui/mod.rs b/src/gui/mod.rs index ee843ba..71babf0 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -76,14 +76,14 @@ impl DecoratedText for &str { } pub fn validate_username(input: &str) -> Result<(), &'static str> { - match input.contains(|ch: char| !ch.is_ascii_alphanumeric() && !"-_ []".contains(ch)) { + match input.contains(|ch: char| !(ch.is_ascii_alphanumeric() || "-_ []@".contains(ch))) { true => Err("invalid username"), false => Ok(()), } } pub fn validate_channel_name(input: &str) -> Result<(), &'static str> { - match input.contains(|ch: char| !ch.is_ascii_alphanumeric() && ch != '#') { + match input.contains(|ch: char| !(ch.is_ascii_alphanumeric() || ch == '#' || ch == '_')) { true => Err("invalid channel name"), false => Ok(()), } diff --git a/src/gui/window.rs b/src/gui/window.rs index 211105d..f2a8f70 100644 --- a/src/gui/window.rs +++ b/src/gui/window.rs @@ -236,9 +236,9 @@ impl ApplicationWindow { } UIMessageIn::ChatSwitchRequested(name, message_id) => { + let lowercase_name = name.to_lowercase(); + self.s.highlights.mark_as_read(&lowercase_name); if self.s.has_chat(&name) { - let lowercase_name = name.to_lowercase(); - self.s.highlights.mark_as_read(&lowercase_name); self.s.active_chat_tab_name = lowercase_name; if message_id.is_some() { self.chat.scroll_to = message_id;