Index: src/mail.rs ================================================================== --- src/mail.rs +++ src/mail.rs @@ -190,11 +190,11 @@ .replace("\r\n", "\n"); // 6: // - (headers) // - (mail text) // - 6: - if text.len() < 4096 - ( reply.len() + 7 ) { + if text.len() < 4096 - ( reply.len() + 6 ) { body = text; text_num = 1; } }; let msg = format!("{}{}", reply, validate(&body).stack()?); Index: src/tests.rs ================================================================== --- src/tests.rs +++ src/tests.rs @@ -13,10 +13,9 @@ Ok(()) } #[test] #[should_panic = "Found special tag while closing generic tag"] -fn check_invalid () -> () { +fn check_invalid () { let html = "

Some valid HTML

Link injection!"; let _ = validate(html).unwrap(); - () } Index: src/utils.rs ================================================================== --- src/utils.rs +++ src/utils.rs @@ -7,11 +7,10 @@ bail, Result, }; lazy_static! { - pub static ref RE_SPECIAL: Regex = Regex::new(r"([\-_*\[\]()~`>#+|{}\.!])").unwrap(); 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])?)*$").unwrap(); } /// `Attachment` object to store number attachment data and corresponding file name #[derive(Debug)] @@ -20,11 +19,15 @@ pub name: String, } /// Pass any text here to be validated as HTML, breaks on validation errors pub fn validate (text: &str) -> Result<&str> { + // Technically full validation is not needed nor required here, all text after validation + // is used in Telegram messages as RAW text enclosed in `pre`/`code` tags, so the only reason + // for this check is to make sure there's no dangling closing tags in the text that might + // break Telegram message formatting let fragment = Html::parse_fragment(text); if !fragment.errors.is_empty() { bail!(fragment.errors.join("\n")); } Ok(text) }