Check-in [6ce625a569]
Logged in as anonymous
Overview
Comment:fix typo, fix comments, drop unneeded constant
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6ce625a56943f462036d14372b29b919fb443ffc9318751b9973053fc6a6b3ab
User & Date: arcade on 2026-01-12 14:46:42.278
Other Links: manifest | tags
Context
2026-01-12
15:13
limit number of job runs check-in: 7551b4dc28 user: arcade tags: trunk
14:46
fix typo, fix comments, drop unneeded constant check-in: 6ce625a569 user: arcade tags: trunk
13:41
minor typos, add back tests, change formatting a lot check-in: c996f5c871 user: arcade tags: trunk
Changes
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
				let text = mail.body_text(0)
					.context("Failed to extract text from message")?
					.replace("\r\n", "\n");
				// 6:
				// - (headers)
				// - (mail text)
				// - 6: </pre>
				if text.len() < 4096 - ( reply.len() + 7 ) {
					body = text;
					text_num = 1;
				}
			};
			let msg = format!("{}{}</pre>", reply, validate(&body).stack()?);

			// and let's collect all other attachment parts







|







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
				let text = mail.body_text(0)
					.context("Failed to extract text from message")?
					.replace("\r\n", "\n");
				// 6:
				// - (headers)
				// - (mail text)
				// - 6: </pre>
				if text.len() < 4096 - ( reply.len() + 6 ) {
					body = text;
					text_num = 1;
				}
			};
			let msg = format!("{}{}</pre>", reply, validate(&body).stack()?);

			// and let's collect all other attachment parts
11
12
13
14
15
16
17
18
19
20
21
22
	let res = validate(html).stack()?;
	assert_eq!(res, html);
	Ok(())
}

#[test]
#[should_panic = "Found special tag while closing generic tag"]
fn check_invalid () -> () {
	let html = "<p>Some <b>valid</b> HTML</p></code><a href='http://somewere.com'>Link injection!</a>";
	let _ = validate(html).unwrap();
	()
}







|


<

11
12
13
14
15
16
17
18
19
20

21
	let res = validate(html).stack()?;
	assert_eq!(res, html);
	Ok(())
}

#[test]
#[should_panic = "Found special tag while closing generic tag"]
fn check_invalid () {
	let html = "<p>Some <b>valid</b> HTML</p></code><a href='http://somewere.com'>Link injection!</a>";
	let _ = validate(html).unwrap();

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24




25
26
27
28
29
30
use crate::Cursor;

use lazy_static::lazy_static;
use regex::Regex;
use scraper::Html;
use stacked_errors::{
	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)]
pub struct Attachment {
	pub data: Cursor<Vec<u8>>,
	pub name: String,
}

/// Pass any text here to be validated as HTML, breaks on validation errors
pub fn validate (text: &str) -> Result<&str> {




	let fragment = Html::parse_fragment(text);
	if !fragment.errors.is_empty() {
		bail!(fragment.errors.join("\n"));
	}
	Ok(text)
}











<












>
>
>
>






1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::Cursor;

use lazy_static::lazy_static;
use regex::Regex;
use scraper::Html;
use stacked_errors::{
	bail,
	Result,
};

lazy_static! {

	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)]
pub struct Attachment {
	pub data: Cursor<Vec<u8>>,
	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)
}