From 6ba65eef71c81aeadd6d148aa7e100e130a7666b Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Wed, 13 Aug 2025 00:27:35 -0300 Subject: [PATCH] Add documentation for discord/sanitizing.rs module and add a few more characters to escape in SanitizeDiscordMarkdown --- src/discord/sanitizing.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/discord/sanitizing.rs b/src/discord/sanitizing.rs index f220c4d..21d617a 100644 --- a/src/discord/sanitizing.rs +++ b/src/discord/sanitizing.rs @@ -1,4 +1,15 @@ +//! Utilities for sanitizing Discord messages (removing markdown from user input). + +/// Escapes Discord markdown in a string. pub trait SanitizeDiscordMarkdown { + /// Escapes Discord markdown in a string. + /// + /// Arguments: + /// * `hard` - If `false`, it'll only escape mentions and pings. Otherwise, it'll also escape + /// generic markdown like headers and code blocks. + /// + /// Returns: + /// [`String`] - The sanitized string. fn sanitize(&self, hard: bool) -> String; } @@ -14,7 +25,8 @@ where for ch in input.chars() { match ch { - '\\' | '*' | '_' | '~' | '`' | '>' | '<' | '|' | '#' => { + '\\' | '*' | '_' | '~' | '`' | '>' | '<' | '|' | '#' | '[' | ']' | '/' + | '(' | ')' => { escaped.push('\\'); escaped.push(ch); }