Skip to content

Commit 0924934

Browse files
committed
When a tag that isn't compatible with Telegram closes, don't force all other markup to reset (but still allow handle_endtag(None) to close all markup).
1 parent b37dc23 commit 0924934

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

metabot/util/html.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def handle_starttag(self, tag, attrs): # pylint: disable=too-many-branches,too-
105105
self.__pieces.append(f'<{tag} {attribute_name}="{escape(attribute_value)}">')
106106

107107
def handle_endtag(self, tag):
108+
if tag and tag not in self.__stack:
109+
return
110+
108111
while self.__stack:
109112
lasttag = self.__stack.pop()
110113
self.__pieces.append(f'</{lasttag}>')

metabot/util/test_html.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,10 @@ def test_MessageEntity_cpp_quirks(): # pylint: disable=invalid-name
149149
assert html.sanitize(
150150
'<code class="language-python">code</code>') == '<code class="language-python">code</code>'
151151
assert html.sanitize('<code class="other">code</code>') == '<code>code</code>'
152+
153+
154+
def test_wellformed_close():
155+
"""Verify well-formed but Telegram-incompatible markup does not close other tags."""
156+
157+
assert html.sanitize(
158+
'hi <code>there <span>friend</span> still') == 'hi <code>there friend still</code>'

0 commit comments

Comments
 (0)