Annotation For src/utils.rs
Logged in as anonymous

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

f5ed284f8c 2025-06-21    1: use crate::Cursor;
f5ed284f8c 2025-06-21    2: 
85fa6bddaa 2026-01-18    3: use std::borrow::Cow;
85fa6bddaa 2026-01-18    4: 
85fa6bddaa 2026-01-18    5: use html_escape::encode_text;
f5ed284f8c 2025-06-21    6: use lazy_static::lazy_static;
bf99298edf 2026-07-31    7: use regex::{
bf99298edf 2026-07-31    8: 	Regex,
bf99298edf 2026-07-31    9: 	RegexBuilder,
bf99298edf 2026-07-31   10: };
0f47e23e21 2026-01-12   11: use stacked_errors::{
0f47e23e21 2026-01-12   12: 	bail,
0f47e23e21 2026-01-12   13: 	Result,
0f47e23e21 2026-01-12   14: };
f5ed284f8c 2025-06-21   15: 
f5ed284f8c 2025-06-21   16: lazy_static! {
3c858ed7c4 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");
bf99298edf 2026-07-31   18: 	pub static ref RE_CLOSING: Regex = RegexBuilder::new(r"</[ \t]*(pre|code)[ \t]*>")
bf99298edf 2026-07-31   19: 		.case_insensitive(true).build().expect("Invalid closing tag regex");
f5ed284f8c 2025-06-21   20: }
f5ed284f8c 2025-06-21   21: 
3c858ed7c4 2026-07-31   22: /// Stores binary attachment data and metadata for Telegram messages.
3c858ed7c4 2026-07-31   23: /// The data is wrapped in a `Cursor<Vec<u8>>` for efficient streaming,
3c858ed7c4 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,
0f47e23e21 2026-01-12   29: }
0f47e23e21 2026-01-12   30: 
dafeec0481 2026-01-18   31: /// Pass any text here to be validated as not breaking from Telegram preformatted blocks
85fa6bddaa 2026-01-18   32: /// escape all HTML chars afterwards
3c858ed7c4 2026-07-31   33: pub fn validate <'a>(text: &'a str) -> Result<Cow<'a, str>> {
dafeec0481 2026-01-18   34: 	if RE_CLOSING.is_match(text) {
dafeec0481 2026-01-18   35: 		bail!("Telegram closing tag found.");
dafeec0481 2026-01-18   36: 	} else {
85fa6bddaa 2026-01-18   37: 		Ok(encode_text(text))
dafeec0481 2026-01-18   38: 	}
f5ed284f8c 2025-06-21   39: }