File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 15
15
"""
16
16
17
17
import html5parser
18
- from constants import voidElements
18
+ from constants import voidElements , contentModelFlags
19
19
import gettext
20
20
_ = gettext .gettext
21
21
22
22
from xml .dom import XHTML_NAMESPACE
23
+ from xml .sax .saxutils import unescape
23
24
24
25
class XMLParser (html5parser .HTMLParser ):
25
26
""" liberal XML parser """
<
10000
path d="m8.177 14.323 2.896-2.896a.25.25 0 0 0-.177-.427H8.75V7.764a.75.75 0 1 0-1.5 0V11H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0ZM2.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75ZM8.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z"> @@ -47,6 +48,11 @@ def normalizeToken(self, token):
47
48
if token ["data" ]:
48
49
self .parseError (_ ("End tag contains unexpected attributes." ))
49
50
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
+
50
56
elif token ["type" ] == "Comment" :
51
57
# Rescue CDATA from the comments
52
58
if (token ["data" ].startswith ("[CDATA[" ) and
Original file line number Diff line number Diff line change @@ -193,16 +193,29 @@ def test_xlink(self):
193
193
194
194
def test_br (self ):
195
195
self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
196
- <head><title>XLINK </title></head>
196
+ <head><title>BR </title></head>
197
197
<body>
198
198
<br/>
199
199
</body></html>""" )
200
200
201
201
def test_strong (self ):
202
202
self .assertXhtmlEquals ("""<html xmlns="http://www.w3.org/1999/xhtml">
203
- <head><title>XLINK </title></head>
203
+ <head><title>STRONG </title></head>
204
204
<body>
205
205
<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>
206
219
</body></html>""" )
207
220
208
221
def buildTestSuite ():
You can’t perform that action at this time.
0 commit comments