From f21a47f2454ec6d0798a92f1780c040fc4e8d242 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Fri, 6 Oct 2023 13:09:14 -0400 Subject: [PATCH] Fix entities inside a tags in linkification (#704) --- bleach/linkifier.py | 2 +- tests/test_linkify.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bleach/linkifier.py b/bleach/linkifier.py index 679d7ead..54a432e1 100644 --- a/bleach/linkifier.py +++ b/bleach/linkifier.py @@ -591,7 +591,7 @@ def __iter__(self): in_a = False token_buffer = [] else: - token_buffer.append(token) + token_buffer.extend(list(self.extract_entities(token))) continue if token["type"] in ["StartTag", "EmptyTag"]: diff --git a/tests/test_linkify.py b/tests/test_linkify.py index bd838133..4cc01a6f 100644 --- a/tests/test_linkify.py +++ b/tests/test_linkify.py @@ -323,6 +323,7 @@ def test_link_fragment(): def test_link_entities_in_qs(): + """Entities in the querystring get escaped""" assert ( linkify("http://xx.com/?a=1&b=2") == 'http://xx.com/?a=1&b=2' @@ -330,9 +331,18 @@ def test_link_entities_in_qs(): def test_link_entities_in_characters_token(): + """Entitites in a Characters token don't get escaped""" assert linkify("foo   bar") == "foo   bar" +def test_link_entities_in_a_tag(): + """Entitites between an a start tag and an a end tag don't get escaped""" + assert ( + linkify('Some entity’s', callbacks=[]) + == 'Some entity’s' + ) + + def test_escaped_html(): """If I pass in escaped HTML, it should probably come out escaped.""" s = "<em>strong</em>"