28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
-
-
+
+
+
+
+
+
+
+
+
+
+
+
|
/// while `name` holds the filename or display name of the attachment.
#[derive(Debug)]
pub struct Attachment {
pub data: Cursor<Vec<u8>>,
pub name: String,
}
/// Pass any text here to be validated as not breaking from Telegram preformatted blocks
/// escape all HTML chars afterwards
/// Validates text to ensure it doesn't break Telegram's preformatted blocks.
///
/// Escapes HTML special characters to prevent injection.
///
/// # Arguments
/// * `text` - Text to validate and escape.
///
/// # Returns
/// * `Result<Cow<'a, str>>` - Escaped text or error if invalid.
///
/// # Errors
/// Returns an error if the text contains Telegram closing tags (`</pre>`, `</code>`).
pub fn validate <'a>(text: &'a str) -> Result<Cow<'a, str>> {
if RE_CLOSING.is_match(text) {
bail!("Telegram closing tag found.");
} else {
Ok(encode_text(text))
}
}
|