fix: accept existing handles with trailing underscores

This commit is contained in:
2026-10-12 00:01:36 +02:00
parent 6563a3d38a
commit 0d69d050ee
3 changed files with 32 additions and 3 deletions
+29 -2
View File
@@ -563,14 +563,13 @@ pub(crate) fn normalize_channel(input: &str) -> io::Result<String> {
.or_else(|| input.strip_prefix("https://youtube.com/"));
let address = url_address.unwrap_or(input);
if let Some(handle) = address.strip_prefix('@') {
// Validate address safety, not creation rules: existing handles can have edge separators.
let length = handle.chars().count();
if length == 0
|| length > 30
|| !handle
.chars()
.all(|c| c.is_alphanumeric() || matches!(c, '_' | '-' | '.'))
|| !handle.starts_with(char::is_alphanumeric)
|| !handle.ends_with(char::is_alphanumeric)
{
return Err(invalid("Invalid YouTube channel handle"));
}
@@ -787,6 +786,34 @@ mod tests {
}
}
#[test]
fn existing_edge_separator_handles_can_be_saved_and_reloaded() {
let channel = "https://www.youtube.com/channel/UC4QobU6STFB0P71PMvOGN5A";
for handle in ["@hontame_", "@_creator", "@.creator-"] {
let directory = TestDirectory::new();
let path = directory.0.join("config.toml");
let tags = BTreeMap::from([("Immersion".to_owned(), true)]);
let saved = set_channel_tags(&path, &tags, handle, channel).unwrap();
assert_eq!(saved.channels[handle], channel);
assert_eq!(saved.categories["Immersion"], [channel]);
let reloaded = load(&path).unwrap();
assert_eq!(reloaded.channels, saved.channels);
assert_eq!(reloaded.categories, saved.categories);
let unchecked = BTreeMap::from([("Immersion".to_owned(), false)]);
set_channel_tags(
&path,
&unchecked,
&format!("https://www.youtube.com/{handle}"),
channel,
)
.unwrap();
let reloaded = load(&path).unwrap();
assert!(reloaded.categories["Immersion"].is_empty());
assert_eq!(reloaded.channels[handle], channel);
assert_eq!(reloaded.channels.len(), 1);
}
}
#[test]
fn key_remaps_survive_all_saves_and_section_orders() {
use crate::keys::{Action, Context};