Annotation For src/utils.rs
Logged in as anonymous

Origin for each line in src/utils.rs from check-in f4660639ca:

f5ed284f8c 2025-06-21    1: use crate::Cursor;
f5ed284f8c 2025-06-21    2: 
1c10bccb4e 2026-01-18    3: use std::borrow::Cow;
1c10bccb4e 2026-01-18    4: 
1c10bccb4e 2026-01-18    5: use html_escape::encode_text;
f5ed284f8c 2025-06-21    6: use lazy_static::lazy_static;
f4660639ca 2026-07-31    7: use regex::{
f4660639ca 2026-07-31    8: 	Regex,
f4660639ca 2026-07-31    9: 	RegexBuilder,
f4660639ca 2026-07-31   10: };
d87e80b9be 2026-01-12   11: use stacked_errors::{
d87e80b9be 2026-01-12   12: 	bail,
d87e80b9be 2026-01-12   13: 	Result,
d87e80b9be 2026-01-12   14: };
f5ed284f8c 2025-06-21   15: 
f5ed284f8c 2025-06-21   16: lazy_static! {
f4660639ca 2026-07-31   17: 	pub static ref RE_DOMAIN: Regex = Regex::new(r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$").expect("Invalid domain regex");
f4660639ca 2026-07-31   18: 	pub static ref RE_CLOSING: Regex = RegexBuilder::new(r"</[ \t]*(pre|code)[ \t]*>")
f4660639ca 2026-07-31   19: 		.case_insensitive(true).build().expect("Invalid closing tag regex");
f5ed284f8c 2025-06-21   20: }
f5ed284f8c 2025-06-21   21: 
f4660639ca 2026-07-31   22: /// Stores binary attachment data and metadata for Telegram messages.
f4660639ca 2026-07-31   23: /// The data is wrapped in a `Cursor<Vec<u8>>` for efficient streaming,
f4660639ca 2026-07-31   24: /// while `name` holds the filename or display name of the attachment.
f5ed284f8c 2025-06-21   25: #[derive(Debug)]
f5ed284f8c 2025-06-21   26: pub struct Attachment {
f5ed284f8c 2025-06-21   27: 	pub data: Cursor<Vec<u8>>,
f5ed284f8c 2025-06-21   28: 	pub name: String,
d87e80b9be 2026-01-12   29: }
d87e80b9be 2026-01-12   30: 
1c10bccb4e 2026-01-18   31: /// Pass any text here to be validated as not breaking from Telegram preformatted blocks
1c10bccb4e 2026-01-18   32: /// escape all HTML chars afterwards
f4660639ca 2026-07-31   33: pub fn validate <'a>(text: &'a str) -> Result<Cow<'a, str>> {
1c10bccb4e 2026-01-18   34: 	if RE_CLOSING.is_match(text) {
1c10bccb4e 2026-01-18   35: 		bail!("Telegram closing tag found.");
1c10bccb4e 2026-01-18   36: 	} else {
1c10bccb4e 2026-01-18   37: 		Ok(encode_text(text))
1c10bccb4e 2026-01-18   38: 	}
f5ed284f8c 2025-06-21   39: }