Escape < > characters for Telegram (#384)

pull/386/head
Chris Caron 2021-05-03 12:41:32 -04:00 committed by GitHub
parent c4fa92824d
commit 7f7ee043d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -547,8 +547,17 @@ class NotifyTelegram(NotifyBase):
body,
)
else: # TEXT
else: # pass directly as is...
payload['parse_mode'] = 'HTML'
# Telegram strangely escapes all HTML characters for us already
# but to avoid causing issues with HTML, we escape the < and >
# characters
title = re.sub('>', '&gt;', title, re.I)
title = re.sub('<', '&lt;', title, re.I)
body = re.sub('>', '&gt;', body, re.I)
body = re.sub('<', '&lt;', body, re.I)
payload['text'] = '{}{}'.format(
'<b>{}</b>\r\n'.format(title) if title else '',
body,