@@ -34,12 +34,16 @@ def get_events(self):
3434
3535 def handle_starttag (self , tag , attrs ):
3636 self .append (("starttag" , tag , attrs ))
37+ if tag == 'svg' :
38+ self .support_cdata (True )
3739
3840 def handle_startendtag (self , tag , attrs ):
3941 self .append (("startendtag" , tag , attrs ))
4042
4143 def handle_endtag (self , tag ):
4244 self .append (("endtag" , tag ))
45+ if tag == 'svg' :
46+ self .support_cdata (False )
4347
4448 # all other markup
4549
@@ -643,10 +647,22 @@ def test_eof_in_declarations(self):
643647 ('<!' , [('comment' , '' )]),
644648 ('<!-' , [('comment' , '-' )]),
645649 ('<![' , [('comment' , '[' )]),
646- ('<![CDATA[' , [('unknown decl' , 'CDATA[' )]),
647- ('<![CDATA[x' , [('unknown decl' , 'CDATA[x' )]),
648- ('<![CDATA[x]' , [('unknown decl' , 'CDATA[x]' )]),
649- ('<![CDATA[x]]' , [('unknown decl' , 'CDATA[x]]' )]),
650+ ('<![CDATA[' , [('comment' , '![CDATA[' )]),
651+ ('<![CDATA[x' , [('comment' , '![CDATA[x' )]),
652+ ('<![CDATA[x]' , [('comment' , '![CDATA[x]' )]),
653+ ('<![CDATA[x]]' , [('comment' , '![CDATA[x]]' )]),
654+ ('<svg><text y="100"><![CDATA[' ,
655+ [('starttag' , 'svg' , []), ('starttag' , 'text' , [('y' , '100' )]),
656+ ('unknown decl' , 'CDATA[' )]),
657+ ('<svg><text y="100"><![CDATA[x' ,
658+ [('starttag' , 'svg' , []), ('starttag' , 'text' , [('y' , '100' )]),
659+ ('unknown decl' , 'CDATA[x' )]),
660+ ('<svg><text y="100"><![CDATA[x]' ,
661+ [('starttag' , 'svg' , []), ('starttag' , 'text' , [('y' , '100' )]),
662+ ('unknown decl' , 'CDATA[x]' )]),
663+ ('<svg><text y="100"><![CDATA[x]]' ,
664+ [('starttag' , 'svg' , []), ('starttag' , 'text' , [('y' , '100' )]),
665+ ('unknown decl' , 'CDATA[x]]' )]),
650666 ('<!DOCTYPE' , [('decl' , 'DOCTYPE' )]),
651667 ('<!DOCTYPE ' , [('decl' , 'DOCTYPE ' )]),
652668 ('<!DOCTYPE html' , [('decl' , 'DOCTYPE html' )]),
@@ -737,11 +753,35 @@ def test_broken_condcoms(self):
737753 ' printf("[<marquee>How?</marquee>]");\n '
738754 ' }\n ' ),
739755 ])
740- def test_cdata_section (self , content ):
756+ def test_cdata_section_content (self , content ):
741757 # See "13.2.5.42 Markup declaration open state",
742758 # "13.2.5.69 CDATA section state", and issue bpo-32876.
743- html = f'<![CDATA[{ content } ]]>'
744- expected = [('unknown decl' , 'CDATA[' + content )]
759+ html = f'<svg><text y="100"><![CDATA[{ content } ]]></text></svg>'
760+ expected = [
761+ ('starttag' , 'svg' , []),
762+ ('starttag' , 'text' , [('y' , '100' )]),
763+ ('unknown decl' , 'CDATA[' + content ),
764+ ('endtag' , 'text' ),
765+ ('endtag' , 'svg' ),
766+ ]
767+ self ._run_check (html , expected )
768+
769+ def test_cdata_section (self ):
770+ # See "13.2.5.42 Markup declaration open state".
771+ html = ('<![CDATA[foo<br>bar]]>'
772+ '<svg><text y="100"><![CDATA[foo<br>bar]]></text></svg>'
773+ '<![CDATA[foo<br>bar]]>' )
774+ expected = [
775+ ('comment' , '[CDATA[foo<br' ),
776+ ('data' , 'bar]]>' ),
777+ ('starttag' , 'svg' , []),
778+ ('starttag' , 'text' , [('y' , '100' )]),
779+ ('unknown decl' , 'CDATA[foo<br>bar' ),
780+ ('endtag' , 'text' ),
781+ ('endtag' , 'svg' ),
782+ ('comment' , '[CDATA[foo<br' ),
783+ ('data' , 'bar]]>' ),
784+ ]
745785 self ._run_check (html , expected )
746786
747787 def test_convert_charrefs_dropped_text (self ):
0 commit comments