mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 02:26:58 -07:00
Use bleach to clean Telegram and Pushover HTML
This commit is contained in:
parent
453c46df00
commit
972412e712
1 changed files with 21 additions and 11 deletions
|
@ -15,6 +15,7 @@
|
|||
|
||||
|
||||
import arrow
|
||||
import bleach
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
|
@ -1112,15 +1113,24 @@ def build_server_notify_text(notify_action=None, agent_id=None):
|
|||
|
||||
|
||||
def strip_tag(data, agent_id=None):
|
||||
# Allow tags b, i, u, a[href], font[color] for Pushover
|
||||
if agent_id == 7:
|
||||
p = re.compile(r'<(?!/?(b>|i>|u>)|(a\shref=\"[^\"\'\s]+\"|/a>|font\scolor=\"[^\"\'\s]+\"|/font>)).*?>',
|
||||
re.IGNORECASE | re.DOTALL)
|
||||
# Allow tags b, i, code, pre, a[href] for Telegram
|
||||
elif agent_id == 13:
|
||||
p = re.compile(r'<(?!/?(b>|i>|code>|pre>)|(a\shref=\"[^\"\'\s]+\"|/a>)).*?>',
|
||||
re.IGNORECASE | re.DOTALL)
|
||||
else:
|
||||
p = re.compile(r'<.*?>', re.IGNORECASE | re.DOTALL)
|
||||
|
||||
return p.sub('', data)
|
||||
if agent_id == 7:
|
||||
# Allow tags b, i, u, a[href], font[color] for Pushover
|
||||
whitelist = {'b': [],
|
||||
'i': [],
|
||||
'u': [],
|
||||
'a': ['href'],
|
||||
'font': ['color']}
|
||||
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
||||
elif agent_id == 13:
|
||||
# Allow tags b, i, code, pre, a[href] for Telegram
|
||||
whitelist = {'b': [],
|
||||
'i': [],
|
||||
'code': [],
|
||||
'pre': [],
|
||||
'a': ['href']}
|
||||
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
||||
|
||||
else:
|
||||
whitelist = {}
|
||||
return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True)
|
Loading…
Add table
Add a link
Reference in a new issue