@@ -1458,6 +1458,8 @@ public final void startTag(ElementName elementName,
1458
1458
flushCharacters ();
1459
1459
1460
1460
// [NOCPP[
1461
+ boolean wasSelfClosing = selfClosing ;
1462
+ boolean voidElement = false ;
1461
1463
if (errorHandler != null ) {
1462
1464
// ID uniqueness
1463
1465
@ IdType String id = attributes .getId ();
@@ -1580,6 +1582,9 @@ public final void startTag(ElementName elementName,
1580
1582
elementName ,
1581
1583
attributes );
1582
1584
selfClosing = false ;
1585
+ // [NOCPP[
1586
+ voidElement = true ;
1587
+ // ]NOCPP]
1583
1588
attributes = null ; // CPP
1584
1589
break starttagloop ;
1585
1590
case TITLE :
@@ -1592,6 +1597,9 @@ public final void startTag(ElementName elementName,
1592
1597
elementName ,
1593
1598
attributes );
1594
1599
selfClosing = false ;
1600
+ // [NOCPP[
1601
+ voidElement = true ;
1602
+ // ]NOCPP]
1595
1603
attributes = null ; // CPP
1596
1604
break starttagloop ;
1597
1605
case SCRIPT :
@@ -1778,6 +1786,9 @@ public final void startTag(ElementName elementName,
1778
1786
attributes ,
1779
1787
formPointer );
1780
1788
selfClosing = false ;
1789
+ // [NOCPP[
1790
+ voidElement = true ;
1791
+ // ]NOCPP]
1781
1792
attributes = null ; // CPP
1782
1793
break starttagloop ;
1783
1794
case FORM :
@@ -2124,6 +2135,9 @@ public final void startTag(ElementName elementName,
2124
2135
elementName ,
2125
2136
attributes );
2126
2137
selfClosing = false ;
2138
+ // [NOCPP[
2139
+ voidElement = true ;
2140
+ // ]NOCPP]
2127
2141
attributes = null ; // CPP
2128
2142
break starttagloop ;
2129
2143
case HR :
@@ -2132,6 +2146,9 @@ public final void startTag(ElementName elementName,
2132
2146
elementName ,
2133
2147
attributes );
2134
2148
selfClosing = false ;
2149
+ // [NOCPP[
2150
+ voidElement = true ;
2151
+ // ]NOCPP]
2135
2152
attributes = null ; // CPP
2136
2153
break starttagloop ;
2137
2154
case IMAGE :
@@ -2145,6 +2162,9 @@ public final void startTag(ElementName elementName,
2145
2162
elementName , attributes ,
2146
2163
formPointer );
2147
2164
selfClosing = false ;
2165
+ // [NOCPP[
2166
+ voidElement = true ;
2167
+ // ]NOCPP]
2148
2168
attributes = null ; // CPP
2149
2169
break starttagloop ;
2150
2170
case TEXTAREA :
@@ -2324,6 +2344,9 @@ public final void startTag(ElementName elementName,
2324
2344
elementName ,
2325
2345
attributes );
2326
2346
selfClosing = false ;
2347
+ // [NOCPP[
2348
+ voidElement = true ;
2349
+ // ]NOCPP]
2327
2350
attributes = null ; // CPP
2328
2351
break starttagloop ;
2329
2352
case META :
@@ -2391,6 +2414,9 @@ public final void startTag(ElementName elementName,
2391
2414
elementName ,
2392
2415
attributes );
2393
2416
selfClosing = false ;
2417
+ // [NOCPP[
2418
+ voidElement = true ;
2419
+ // ]NOCPP]
2394
2420
attributes = null ; // CPP
2395
2421
break starttagloop ;
2396
2422
case META :
@@ -2399,6 +2425,9 @@ public final void startTag(ElementName elementName,
2399
2425
elementName ,
2400
2426
attributes );
2401
2427
selfClosing = false ;
2428
+ // [NOCPP[
2429
+ voidElement = true ;
2430
+ // ]NOCPP]
2402
2431
attributes = null ; // CPP
2403
2432
break starttagloop ;
2404
2433
case STYLE :
@@ -2438,6 +2467,9 @@ public final void startTag(ElementName elementName,
2438
2467
elementName ,
2439
2468
attributes );
2440
2469
selfClosing = false ;
2470
+ // [NOCPP[
2471
+ voidElement = true ;
2472
+ // ]NOCPP]
2441
2473
attributes = null ; // CPP
2442
2474
break starttagloop ;
2443
2475
case TEMPLATE :
@@ -2572,6 +2604,9 @@ public final void startTag(ElementName elementName,
2572
2604
elementName ,
2573
2605
attributes );
2574
2606
selfClosing = false ;
2607
+ // [NOCPP[
2608
+ voidElement = true ;
2609
+ // ]NOCPP]
2575
2610
attributes = null ; // CPP
2576
2611
break starttagloop ;
2577
2612
default :
@@ -2745,6 +2780,9 @@ public final void startTag(ElementName elementName,
2745
2780
elementName ,
2746
2781
attributes );
2747
2782
selfClosing = false ;
2783
+ // [NOCPP[
2784
+ voidElement = true ;
2785
+ // ]NOCPP]
2748
2786
pop (); // head
2749
2787
attributes = null ; // CPP
2750
2788
break starttagloop ;
@@ -2756,6 +2794,9 @@ public final void startTag(ElementName elementName,
2756
2794
elementName ,
2757
2795
attributes );
2758
2796
selfClosing = false ;
2797
+ // [NOCPP[
2798
+ voidElement = true ;
2799
+ // ]NOCPP]
2759
2800
pop (); // head
2760
2801
attributes = null ; // CPP
2761
2802
break starttagloop ;
@@ -2844,6 +2885,18 @@ public final void startTag(ElementName elementName,
2844
2885
}
2845
2886
if (selfClosing ) {
2846
2887
errSelfClosing ();
2888
+ // [NOCPP[
2889
+ } else if (wasSelfClosing && voidElement
2890
+ && tokenizer .getErrorProfile () != null
2891
+ && tokenizer .getErrorProfile ().get ("html-strict" ) != null ) {
2892
+ warn ("Self-closing tag syntax in text/html documents is widely"
2893
+ + " discouraged; it’s unnecessary and interacts badly"
2894
+ + " with other HTML features (e.g., unquoted attribute"
2895
+ + " values). If you’re using a tool that injects"
2896
+ + " self-closing tag syntax into all void elements,"
2897
+ + " without any option to prevent it from doing so,"
2898
+ + " then consider switching to a different tool." );
2899
+ // ]NOCPP]
2847
2900
}
2848
2901
// CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) {
2849
2902
// CPPONLY: Portability.delete(attributes);
0 commit comments