@@ -1247,7 +1247,12 @@ def check(p, expected, namespaces=None):
12471247 {'' : 'http://www.w3.org/2001/XMLSchema' ,
12481248 'ns' : 'http://www.w3.org/2001/XMLSchema' })
12491249
1250- def test_processinginstruction (self ):
1250+ def test_comment_serialization (self ):
1251+ comm = ET .Comment ('<spam> & ham' )
1252+ # comments are not escaped
1253+ self .assertEqual (ET .tostring (comm ), b'<!--<spam> & ham-->' )
1254+
1255+ def test_processinginstruction_serialization (self ):
12511256 # Test ProcessingInstruction directly
12521257
12531258 self .assertEqual (ET .tostring (ET .ProcessingInstruction ('test' , 'instruction' )),
@@ -1256,13 +1261,22 @@ def test_processinginstruction(self):
12561261 b'<?test instruction?>' )
12571262
12581263 # Issue #2746
1259-
1264+ # processing instructions are not escaped
12601265 self .assertEqual (ET .tostring (ET .PI ('test' , '<testing&>' )),
12611266 b'<?test <testing&>?>' )
12621267 self .assertEqual (ET .tostring (ET .PI ('test' , '<testing&>\xe3 ' ), 'latin-1' ),
12631268 b"<?xml version='1.0' encoding='latin-1'?>\n "
12641269 b"<?test <testing&>\xe3 ?>" )
12651270
1271+ @support .subTests ('tag' , ("script" , "style" , "xmp" , "iframe" , "noembed" , "noframes" ))
1272+ def test_html_cdata_elems_serialization (self , tag ):
1273+ # content of raw text elements is not escaped in html
1274+ tag = tag .title ()
1275+ elem = ET .Element (tag )
1276+ elem .text = '<spam>&ham'
1277+ self .assertEqual (ET .tostring (elem , method = 'html' ),
1278+ ('<%s><spam>&ham</%s>' % (tag , tag )).encode ())
1279+
12661280 def test_html_empty_elems_serialization (self ):
12671281 # issue 15970
12681282 # from http://www.w3.org/TR/html401/index/elements.html
@@ -1277,6 +1291,14 @@ def test_html_empty_elems_serialization(self):
12771291 method = 'html' )
12781292 self .assertEqual (serialized , expected )
12791293
1294+ def test_html_plaintext_serialization (self ):
1295+ # content of plaintext is not escaped in html
1296+ # no end tag for plaintext
1297+ elem = ET .Element ('PlainText' )
1298+ elem .text = '<spam>&ham'
1299+ self .assertEqual (ET .tostring (elem , method = 'html' ),
1300+ b'<PlainText><spam>&ham' )
1301+
12801302 def test_dump_attribute_order (self ):
12811303 # See BPO 34160
12821304 e = ET .Element ('cirriculum' , status = 'public' , company = 'example' )
0 commit comments