Skip to content

Commit

Permalink
escape more characters when sanitizing for markdown (#1681)
Browse files Browse the repository at this point in the history
Co-authored-by: jasquat <[email protected]>
  • Loading branch information
jasquat and jasquat authored Jun 5, 2024
1 parent fc8b81e commit 4611628
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ def get_helper_mapping(cls) -> dict:
@classmethod
def sanitize_for_md(cls, value: str) -> str:
"""Sanitizes given value for markdown."""
sanitized_value = re.sub(r"([|])", r"\\\1", value)
return sanitized_value
# modified from https://github.com/python-telegram-bot/python-telegram-bot/blob/1fdaaac8094c9d76c34c8c8e8c9add16080e75e7/telegram/utils/helpers.py#L149
escape_chars = r"_*[]()~`>#+-=|{}!"
escaped_value = re.sub(f"([{re.escape(escape_chars)}])", r"\\\1", value)
escaped_value = escaped_value.replace("\n", "").replace("\r", "")
return escaped_value


class JinjaService:
Expand Down

0 comments on commit 4611628

Please sign in to comment.