Skip to content

gh-118350: Add escapable-raw-text mode to html parser #121770

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

Closed
wants to merge 10 commits into from
Prev Previous commit
test: add charref test
  • Loading branch information
timonviola committed May 14, 2025
commit 70b8e5d6b7beea975c68ba5ef6c4138255b79779
34 changes: 31 additions & 3 deletions Lib/test/test_htmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ def test_cdata_content(self):
self._run_check(s, [("starttag", element_lower, []),
("data", content),
("endtag", element_lower)])

def test_raw_text_content(self):
"""See gh-issue #118350"""
# Tags should be treated as text in raw text and escapable raw text content.
content = """<h1>tagshould be handled as text"""
elements = [
"script",
Expand All @@ -318,6 +319,33 @@ def test_raw_text_content(self):
("data", content)
])

def test_escapable_raw_text_content(self):
# Charrefs should be escaped in esacapable raw text content.
class Collector(EventCollector):
pass

content = "Timon &amp; Pumba"
expected = "Timon & Pumba"
elements = [
"title",
"textarea",
"TITLE",
"TEXTAREA",
"Title",
"Textarea",
]
for element in elements:
source = f"<{element}>{content}"
self._run_check(
source, [
("starttag", element.lower(), []),
('data', 'Timon '),
('entityref', 'amp'),
('data', ' Pumba')
],
collector=Collector(convert_charrefs=False),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean this test? @serhiy-storchaka

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thanks.

)

def test_cdata_with_closing_tags(self):
# see issue #13358
# make sure that HTMLParser calls handle_data only once for each CDATA.
Expand Down Expand Up @@ -496,7 +524,7 @@ def test_slashes_in_starttag(self):
('starttag', 'a', [('foo', None), ('=', None), ('bar', None)])
]
self._run_check(html, expected)
#see issue #14538
# see issue #14538
html = ('<meta><meta / ><meta // ><meta / / >'
'<meta/><meta /><meta //><meta//>')
expected = [
Expand Down Expand Up @@ -909,4 +937,4 @@ def test_base_class_methods_called(self, super_reset_method, super_init_method):


if __name__ == "__main__":
unittest.main()
unittest.main()
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy