Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML tag cleaning #2177

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions chatcommands.py
Expand Up @@ -24,7 +24,7 @@
from ast import literal_eval
# noinspection PyCompatibility
import regex
from helpers import only_blacklists_changed
from helpers import only_blacklists_changed, clean_html
from classes import Post
from classes.feedback import *

Expand Down Expand Up @@ -245,7 +245,7 @@ def do_blacklist(raw_pattern, blacklist_type, msg, force=False):
id=msg.owner.id)

# noinspection PyProtectedMember
pattern = rebuild_str(raw_pattern)
pattern = clean_html(rebuild_str(raw_pattern))
try:
regex.compile(pattern)
except regex._regex_core.error:
Expand Down
9 changes: 9 additions & 0 deletions helpers.py
Expand Up @@ -103,5 +103,14 @@ def api_parameter_from_link(link):
return None


def clean_html(raw_message):
"""
Removes some HTML tags from input and replaces it with markdown
"""
raw_message = regex.subf("<i>(.+?)</i>", "*{1}*", raw_message)
raw_message = regex.subf("<b>(.+?)</b>", "**{1}**", raw_message)
return regex.subf("<code>(.+?)</code>", "`{1}`", raw_message)


class SecurityError(Exception):
pass