@@ -324,49 +324,138 @@ def test_style_content(self, content):
324
324
("data" , content ),
325
325
("endtag" , "style" )])
326
326
327
- @support .subTests ('content' , [
328
- '<!-- not a comment -->' ,
329
- "<not a='start tag'>" ,
330
- '<![CDATA[not a cdata]]>' ,
331
- '<!not a bogus comment>' ,
332
- '</not a bogus comment>' ,
333
- '\u2603 ' ,
334
- '< /title>' ,
335
- '</ title>' ,
336
- '</titled>' ,
337
- '</title\v >' ,
338
- '</title\xa0 >' ,
339
- '</tıtle>' ,
327
+ @support .subTests ('tag' , ['title' , 'textarea' ])
328
+ def test_rcdata_content (self , tag ):
329
+ content = (
330
+ '<!-- not a comment -->'
331
+ "<not a='start tag'>"
332
+ '<![CDATA[not a cdata]]>'
333
+ '<!not a bogus comment>'
334
+ '</not a bogus comment>'
335
+ '\u2603 '
336
+ f'< /{ tag } >'
337
+ f'</ { tag } >'
338
+ f'</{ tag } x>'
339
+ f'</{ tag } \v >'
340
+ f'</{ tag } \xa0 >'
341
+ )
342
+ source = f"<{ tag } >{ content } </{ tag } >"
343
+ self ._run_check (source , [
344
+ ("starttag" , tag , []),
345
+ ("data" , content ),
346
+ ("endtag" , tag ),
340
347
])
341
- def test_title_content (self , content ):
342
- source = f"<title>{ content } </title>"
348
+ source = f"<{ tag } >&</{ tag } >"
343
349
self ._run_check (source , [
344
- ("starttag" , "title" , []),
350
+ ("starttag" , tag , []),
351
+ ('entityref' , 'amp' ),
352
+ ("endtag" , tag ),
353
+ ])
354
+
355
+ @support .subTests ('tag' ,
356
+ ['style' , 'xmp' , 'iframe' , 'noembed' , 'noframes' , 'script' ])
357
+ def test_rawtext_content (self , tag ):
358
+ content = (
359
+ '<!-- not a comment -->'
360
+ '¬-an-entity-ref;'
361
+ "<not a='start tag'>"
362
+ '<![CDATA[not a cdata]]>'
363
+ '<!not a bogus comment>'
364
+ '</not a bogus comment>'
365
+ '\u2603 '
366
+ f'< /{ tag } >'
367
+ f'</ { tag } >'
368
+ f'</{ tag } x>'
369
+ f'</{ tag } \v >'
370
+ f'</{ tag } \xa0 >'
371
+ )
372
+ source = f"<{ tag } >{ content } </{ tag } >"
373
+ self ._run_check (source , [
374
+ ("starttag" , tag , []),
345
375
("data" , content ),
346
- ("endtag" , "title" ),
376
+ ("endtag" , tag ),
347
377
])
348
378
349
- @support .subTests ('content' , [
350
- '<!-- not a comment -->' ,
351
- "<not a='start tag'>" ,
352
- '<![CDATA[not a cdata]]>' ,
353
- '<!not a bogus comment>' ,
354
- '</not a bogus comment>' ,
355
- '\u2603 ' ,
356
- '< /textarea>' ,
357
- '</ textarea>' ,
358
- '</textareable>' ,
359
- '</textarea\v >' ,
360
- '</textarea\xa0 >' ,
379
+ def test_noscript_content (self ):
380
+ content = (
381
+ '<!-- not a comment -->'
382
+ '¬-an-entity-ref;'
383
+ "<not a='start tag'>"
384
+ '<![CDATA[not a cdata]]>'
385
+ '<!not a bogus comment>'
386
+ '</not a bogus comment>'
387
+ '\u2603 '
388
+ f'< /noscript>'
389
+ f'</ noscript>'
390
+ f'</noscriptx>'
391
+ f'</noscript\v >'
392
+ f'</noscript\xa0 >'
393
+ )
394
+ source = f"<noscript>{ content } </noscript>"
395
+ self ._run_check (source , [
396
+ ('starttag' , 'noscript' , []),
397
+ ('comment' , ' not a comment ' ),
398
+ ('entityref' , 'not' ),
399
+ ('data' , '-an-entity-ref;' ),
400
+ ('starttag' , 'not' , [('a' , 'start tag' )]),
401
+ ('unknown decl' , 'CDATA[not a cdata' ),
402
+ ('comment' , 'not a bogus comment' ),
403
+ ('endtag' , 'not' ),
404
+ ('data' , '☃< /noscript>' ),
405
+ ('comment' , ' noscript' ),
406
+ ('endtag' , 'noscriptx' ),
407
+ ('endtag' , 'noscript\x0b ' ),
408
+ ('endtag' , 'noscript\xa0 ' ),
409
+ ('endtag' , 'noscript' )
361
410
])
362
- def test_textarea_content (self , content ):
363
- source = f"<textarea>{ content } </textarea>"
364
411
self ._run_check (source , [
365
- ("starttag" , "textarea" , []),
412
+ ("starttag" , "noscript" , []),
413
+ ("data" , content ),
414
+ ("endtag" , "noscript" ),
415
+ ], collector = EventCollector (convert_charrefs = False , scripting = True ))
416
+
417
+ def test_plaintext_content (self ):
418
+ content = (
419
+ '<!-- not a comment -->'
420
+ '¬-an-entity-ref;'
421
+ "<not a='start tag'>"
422
+ '<![CDATA[not a cdata]]>'
423
+ '<!not a bogus comment>'
424
+ '</not a bogus comment>'
425
+ '\u2603 '
426
+ '</plaintext>'
427
+ )
428
+ source = f"<plaintext>{ content } "
429
+ self ._run_check (source , [
430
+ ("starttag" , "plaintext" , []),
366
431
("data" , content ),
367
- ("endtag" , "textarea" ),
368
432
])
369
433
434
+ @support .subTests ('tag,endtag' , [
435
+ ('title' , 'tıtle' ),
436
+ ('style' , 'ſtyle' ),
437
+ ('style' , 'ſtyle' ),
438
+ ('style' , 'style' ),
439
+ ('iframe' , 'ıframe' ),
440
+ ('noframes' , 'noframeſ' ),
441
+ ('noscript' , 'noſcript' ),
442
+ ('noscript' , 'noscrıpt' ),
443
+ ('script' , 'ſcript' ),
444
+ ('script' , 'scrıpt' ),
445
+ ])
446
+ def test_invalid_nonascii_closing_tag (self , tag , endtag ):
447
+ source = f"<{ tag } ><a></{ endtag } >"
448
+ self ._run_check (source , [
449
+ ("starttag" , tag , []),
450
+ ("data" , f"<a></{ endtag } >" ),
451
+ ], collector = EventCollector (convert_charrefs = False , scripting = True ))
452
+ source = f"<{ tag } ><a></{ endtag } ></{ tag } >"
453
+ self ._run_check (source , [
454
+ ("starttag" , tag , []),
455
+ ("data" , f"<a></{ endtag } >" ),
456
+ ("endtag" , tag ),
457
+ ], collector = EventCollector (convert_charrefs = False , scripting = True ))
458
+
370
459
@support .subTests ('endtag' , ['script' , 'SCRIPT' , 'script ' , 'script\n ' ,
371
460
'script/' , 'script foo=bar' , 'script foo=">"' ])
372
461
def test_script_closing_tag (self , endtag ):
@@ -428,6 +517,20 @@ def test_textarea_closing_tag(self, endtag):
428
517
("endtag" , "textarea" )],
429
518
collector = EventCollectorNoNormalize (convert_charrefs = False ))
430
519
520
+ @support .subTests ('starttag' , ['TitLe' , 'TexTarEa' , 'StyLE' , 'XmP' ,
521
+ 'iFraMe' , 'noEmBed' , 'noFraMes' , 'noScrIPt' ,
522
+ 'ScrIPt' ])
523
+ def test_closing_tag (self , starttag ):
524
+ tag = starttag .lower ()
525
+ for endtag in [tag , tag .upper (), f'{ tag } ' , f'{ tag } \n ' ,
526
+ f'{ tag } /' , f'{ tag } foo=bar' , f'{ tag } foo=">"' ]:
527
+ content = "<!-- not a comment --><i>Spam</i>"
528
+ s = f'<{ starttag } >{ content } </{ endtag } >'
529
+ self ._run_check (s , [("starttag" , tag , []),
530
+ ('data' , content ),
531
+ ("endtag" , tag )],
532
+ collector = EventCollectorNoNormalize (convert_charrefs = False , scripting = True ))
533
+
431
534
@support .subTests ('tail,end' , [
432
535
('' , False ),
433
536
('<' , False ),
0 commit comments