1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-05-30 08:36:47 +02:00

Document static regex invariants

This commit is contained in:
TheGeneralist 2026-05-29 16:43:34 +02:00
parent 44a563463b
commit 311ed34394
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -220,7 +220,8 @@ fn determine_source(path: &str) -> Source {
return Source::Local; return Source::Local;
} else if path.starts_with("http://") || path.starts_with("https://") { } else if path.starts_with("http://") || path.starts_with("https://") {
// Video URLs (watch, youtu.be, shorts) // Video URLs (watch, youtu.be, shorts)
let video_re = regex::Regex::new(r"^https?://(?:www\.)?(?:youtu\.be/[0-9A-Za-z_-]+|youtube\.com/watch\?v=[0-9A-Za-z_-]+|youtube\.com/shorts/[0-9A-Za-z_-]+)").unwrap(); let video_re = regex::Regex::new(r"^https?://(?:www\.)?(?:youtu\.be/[0-9A-Za-z_-]+|youtube\.com/watch\?v=[0-9A-Za-z_-]+|youtube\.com/shorts/[0-9A-Za-z_-]+)")
.expect("YouTube video URL regex literal must be valid");
if video_re.is_match(path) { if video_re.is_match(path) {
return Source::YouTubeVideo; return Source::YouTubeVideo;
} }
@ -228,13 +229,14 @@ fn determine_source(path: &str) -> Source {
// Playlist URLs // Playlist URLs
let playlist_re = let playlist_re =
regex::Regex::new(r"^https?://(?:www\.)?youtube\.com/playlist\?list=[0-9A-Za-z_-]+") regex::Regex::new(r"^https?://(?:www\.)?youtube\.com/playlist\?list=[0-9A-Za-z_-]+")
.unwrap(); .expect("YouTube playlist URL regex literal must be valid");
if playlist_re.is_match(path) { if playlist_re.is_match(path) {
return Source::YouTubePlaylist; return Source::YouTubePlaylist;
} }
// Channel or user URLs (channel IDs, /c/, /user/, or @handles) // Channel or user URLs (channel IDs, /c/, /user/, or @handles)
let channel_re = regex::Regex::new(r"^https?://(?:www\.)?youtube\.com/(?:channel/[0-9A-Za-z_-]+|c/[0-9A-Za-z_-]+|user/[0-9A-Za-z_-]+|@[0-9A-Za-z_-]+)").unwrap(); let channel_re = regex::Regex::new(r"^https?://(?:www\.)?youtube\.com/(?:channel/[0-9A-Za-z_-]+|c/[0-9A-Za-z_-]+|user/[0-9A-Za-z_-]+|@[0-9A-Za-z_-]+)")
.expect("YouTube channel URL regex literal must be valid");
if channel_re.is_match(path) { if channel_re.is_match(path) {
return Source::YouTubeChannel; return Source::YouTubeChannel;
} }