Skip to content

Commit 46dc8c5

Browse files
committed
Add further tests
1 parent ce10cf8 commit 46dc8c5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

tdom/parser_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from markupsafe import Markup
23

34
from .nodes import Comment, DocumentType, Element, Fragment, Text
45
from .parser import parse_html
@@ -149,11 +150,20 @@ def test_parse_mixed_content():
149150
)
150151

151152

153+
def test_parse_entities_are_escaped():
154+
node = parse_html("<p>&lt;/p&gt;</p>")
155+
assert node == Element(
156+
"p",
157+
children=[Text("</p>")],
158+
)
159+
assert str(node) == "<p>&lt;/p&gt;</p>"
160+
161+
152162
def test_parse_script_tag_content():
153163
node = parse_html("<script>if (a < b && c > d) { alert('wow'); }</script>")
154164
assert node == Element(
155165
"script",
156-
children=[Text("if (a < b && c > d) { alert('wow'); }")],
166+
children=[Text(Markup("if (a < b && c > d) { alert('wow'); }"))],
157167
)
158168
assert str(node) == ("<script>if (a < b && c > d) { alert('wow'); }</script>")
159169

@@ -163,7 +173,7 @@ def test_parse_script_with_entities():
163173
node = parse_html("<script>var x = 'a &amp; b';</script>")
164174
assert node == Element(
165175
"script",
166-
children=[Text("var x = 'a &amp; b';")],
176+
children=[Text(Markup("var x = 'a &amp; b';"))],
167177
)
168178
assert str(node) == "<script>var x = 'a &amp; b';</script>"
169179

@@ -172,7 +182,7 @@ def test_parse_textarea_tag_content():
172182
node = parse_html("<textarea>if (a < b && c > d) { alert('wow'); }</textarea>")
173183
assert node == Element(
174184
"textarea",
175-
children=[Text("if (a < b && c > d) { alert('wow'); }")],
185+
children=[Text(Markup("if (a < b && c > d) { alert('wow'); }"))],
176186
)
177187
assert str(node) == "<textarea>if (a < b && c > d) { alert('wow'); }</textarea>"
178188

@@ -182,7 +192,7 @@ def test_parse_textarea_with_entities():
182192
node = parse_html("<textarea>var x = 'a &amp; b';</textarea>")
183193
assert node == Element(
184194
"textarea",
185-
children=[Text("var x = 'a & b';")],
195+
children=[Text(Markup("var x = 'a & b';"))],
186196
)
187197
assert str(node) == "<textarea>var x = 'a & b';</textarea>"
188198

@@ -191,7 +201,7 @@ def test_parse_title_unusual():
191201
node = parse_html("<title>My & Awesome <Site></title>")
192202
assert node == Element(
193203
"title",
194-
children=[Text("My & Awesome <Site>")],
204+
children=[Text(Markup("My & Awesome <Site>"))],
195205
)
196206
assert str(node) == "<title>My & Awesome <Site></title>"
197207

tdom/processor_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def test_parse_nested_elements():
8888
assert str(node) == "<div><p>Hello</p><p>World</p></div>"
8989

9090

91+
def test_parse_entities_are_escaped():
92+
node = html(t"<p>&lt;/p&gt;</p>")
93+
assert node == Element(
94+
"p",
95+
children=[Text("</p>")],
96+
)
97+
assert str(node) == "<p>&lt;/p&gt;</p>"
98+
99+
91100
# --------------------------------------------------------------------------
92101
# Interpolated text content
93102
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)