@@ -323,6 +323,16 @@ def get_events(self):
323323 ("endtag" , element_lower )],
324324 collector = Collector ())
325325
326+ def test_condcoms (self ):
327+ html = ('<!--[if IE & !(lte IE 8)]>aren\' t<![endif]-->'
328+ '<!--[if IE 8]>condcoms<![endif]-->'
329+ '<!--[if lte IE 7]>pretty?<![endif]-->' )
330+ expected = [('comment' , "[if IE & !(lte IE 8)]>aren't<![endif]" ),
331+ ('comment' , '[if IE 8]>condcoms<![endif]' ),
332+ ('comment' , '[if lte IE 7]>pretty?<![endif]' )]
333+ self ._run_check (html , expected )
334+
335+
326336class HTMLParserTolerantTestCase (HTMLParserStrictTestCase ):
327337
328338 def get_collector (self ):
@@ -416,6 +426,39 @@ def test_unescape_function(self):
416426 # see #12888
417427 self .assertEqual (p .unescape ('{ ' * 1050 ), '{ ' * 1050 )
418428
429+ def test_broken_condcoms (self ):
430+ # these condcoms are missing the '--' after '<!' and before the '>'
431+ html = ('<![if !(IE)]>broken condcom<![endif]>'
432+ '<![if ! IE]><link href="favicon.tiff"/><![endif]>'
433+ '<![if !IE 6]><img src="firefox.png" /><![endif]>'
434+ '<![if !ie 6]><b>foo</b><![endif]>'
435+ '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>' )
436+ # According to the HTML5 specs sections "8.2.4.44 Bogus comment state"
437+ # and "8.2.4.45 Markup declaration open state", comment tokens should
438+ # be emitted instead of 'unknown decl', but calling unknown_decl
439+ # provides more flexibility.
440+ # See also Lib/_markupbase.py:parse_declaration
441+ expected = [
442+ ('unknown decl' , 'if !(IE)' ),
443+ ('data' , 'broken condcom' ),
444+ ('unknown decl' , 'endif' ),
445+ ('unknown decl' , 'if ! IE' ),
446+ ('startendtag' , 'link' , [('href' , 'favicon.tiff' )]),
447+ ('unknown decl' , 'endif' ),
448+ ('unknown decl' , 'if !IE 6' ),
449+ ('startendtag' , 'img' , [('src' , 'firefox.png' )]),
450+ ('unknown decl' , 'endif' ),
451+ ('unknown decl' , 'if !ie 6' ),
452+ ('starttag' , 'b' , []),
453+ ('data' , 'foo' ),
454+ ('endtag' , 'b' ),
455+ ('unknown decl' , 'endif' ),
456+ ('unknown decl' , 'if (!IE)|(lt IE 9)' ),
457+ ('startendtag' , 'img' , [('src' , 'mammoth.bmp' )]),
458+ ('unknown decl' , 'endif' )
459+ ]
460+ self ._run_check (html , expected )
461+
419462
420463class AttributesStrictTestCase (TestCaseBase ):
421464
0 commit comments