File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515"""
1616
1717import html5parser
18- from constants import voidElements
18+ from constants import voidElements , contentModelFlags
1919import gettext
2020_ = gettext .gettext
2121
2222from xml .dom import XHTML_NAMESPACE
23+ from xml .sax .saxutils import unescape
2324
2425class XMLParser (html5parser .HTMLParser ):
2526 """ liberal XML parser """
@@ -47,6 +48,11 @@ def normalizeToken(self, token):
4748 if token ["data" ]:
4849 self .parseError (_ ("End tag contains unexpected attributes." ))
4950
51+ elif token ["type" ] == "Characters" :
52+ # un-escape rcdataElements (e.g. style, script)
53+ if self .tokenizer .contentModelFlag == contentModelFlags ["CDATA" ]:
54+ token ["data" ] = unescape (token ["data" ])
55+
5056 elif token ["type" ] == "Comment" :
5157 # Rescue CDATA from the comments
5258 if (token ["data" ].startswith ("[CDATA[" ) and
Original file line number Diff line number Diff line change @@ -193,16 +193,29 @@ def test_xlink(self):
193193
194194 def test_br (self ):
195195 self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
196- <head><title>XLINK </title></head>
196+ <head><title>BR </title></head>
197197<body>
198198<br/>
199199</body></html>""" )
200200
201201 def test_strong (self ):
202202 self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
203- <head><title>XLINK </title></head>
203+ <head><title>STRONG </title></head>
204204<body>
205205<strong></strong>
206+ </body></html>""" )
207+
208+ def test_script (self ):
209+ self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
210+ <head><title>SCRIPT</title></head>
211+ <body>
212+ <script>1 < 2 & 3</script>
213+ </body></html>""" )
214+
215+ def test_title (self ):
216+ self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
217+ <head><title>1 < 2 & 3</title></head>
218+ <body>
206219</body></html>""" )
207220
208221def buildTestSuite ():
You can’t perform that action at this time.
0 commit comments