11import pytest
2+ from markupsafe import Markup
23
34from .nodes import Comment , DocumentType , Element , Fragment , Text
45from .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></p></p>" )
155+ assert node == Element (
156+ "p" ,
157+ children = [Text ("</p>" )],
158+ )
159+ assert str (node ) == "<p></p></p>"
160+
161+
152162def 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 & b';</script>" )
164174 assert node == Element (
165175 "script" ,
166- children = [Text ("var x = 'a & b';" )],
176+ children = [Text (Markup ( "var x = 'a & b';" ) )],
167177 )
168178 assert str (node ) == "<script>var x = 'a & 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 & 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
0 commit comments