@@ -1458,6 +1458,8 @@ public final void startTag(ElementName elementName,
14581458 flushCharacters ();
14591459
14601460 // [NOCPP[
1461+ boolean wasSelfClosing = selfClosing ;
1462+ boolean voidElement = false ;
14611463 if (errorHandler != null ) {
14621464 // ID uniqueness
14631465 @ IdType String id = attributes .getId ();
@@ -1580,6 +1582,9 @@ public final void startTag(ElementName elementName,
15801582 elementName ,
15811583 attributes );
15821584 selfClosing = false ;
1585+ // [NOCPP[
1586+ voidElement = true ;
1587+ // ]NOCPP]
15831588 attributes = null ; // CPP
15841589 break starttagloop ;
15851590 case TITLE :
@@ -1592,6 +1597,9 @@ public final void startTag(ElementName elementName,
15921597 elementName ,
15931598 attributes );
15941599 selfClosing = false ;
1600+ // [NOCPP[
1601+ voidElement = true ;
1602+ // ]NOCPP]
15951603 attributes = null ; // CPP
15961604 break starttagloop ;
15971605 case SCRIPT :
@@ -1778,6 +1786,9 @@ public final void startTag(ElementName elementName,
17781786 attributes ,
17791787 formPointer );
17801788 selfClosing = false ;
1789+ // [NOCPP[
1790+ voidElement = true ;
1791+ // ]NOCPP]
17811792 attributes = null ; // CPP
17821793 break starttagloop ;
17831794 case FORM :
@@ -2124,6 +2135,9 @@ public final void startTag(ElementName elementName,
21242135 elementName ,
21252136 attributes );
21262137 selfClosing = false ;
2138+ // [NOCPP[
2139+ voidElement = true ;
2140+ // ]NOCPP]
21272141 attributes = null ; // CPP
21282142 break starttagloop ;
21292143 case HR :
@@ -2132,6 +2146,9 @@ public final void startTag(ElementName elementName,
21322146 elementName ,
21332147 attributes );
21342148 selfClosing = false ;
2149+ // [NOCPP[
2150+ voidElement = true ;
2151+ // ]NOCPP]
21352152 attributes = null ; // CPP
21362153 break starttagloop ;
21372154 case IMAGE :
@@ -2145,6 +2162,9 @@ public final void startTag(ElementName elementName,
21452162 elementName , attributes ,
21462163 formPointer );
21472164 selfClosing = false ;
2165+ // [NOCPP[
2166+ voidElement = true ;
2167+ // ]NOCPP]
21482168 attributes = null ; // CPP
21492169 break starttagloop ;
21502170 case TEXTAREA :
@@ -2324,6 +2344,9 @@ public final void startTag(ElementName elementName,
23242344 elementName ,
23252345 attributes );
23262346 selfClosing = false ;
2347+ // [NOCPP[
2348+ voidElement = true ;
2349+ // ]NOCPP]
23272350 attributes = null ; // CPP
23282351 break starttagloop ;
23292352 case META :
@@ -2391,6 +2414,9 @@ public final void startTag(ElementName elementName,
23912414 elementName ,
23922415 attributes );
23932416 selfClosing = false ;
2417+ // [NOCPP[
2418+ voidElement = true ;
2419+ // ]NOCPP]
23942420 attributes = null ; // CPP
23952421 break starttagloop ;
23962422 case META :
@@ -2399,6 +2425,9 @@ public final void startTag(ElementName elementName,
23992425 elementName ,
24002426 attributes );
24012427 selfClosing = false ;
2428+ // [NOCPP[
2429+ voidElement = true ;
2430+ // ]NOCPP]
24022431 attributes = null ; // CPP
24032432 break starttagloop ;
24042433 case STYLE :
@@ -2438,6 +2467,9 @@ public final void startTag(ElementName elementName,
24382467 elementName ,
24392468 attributes );
24402469 selfClosing = false ;
2470+ // [NOCPP[
2471+ voidElement = true ;
2472+ // ]NOCPP]
24412473 attributes = null ; // CPP
24422474 break starttagloop ;
24432475 case TEMPLATE :
@@ -2572,6 +2604,9 @@ public final void startTag(ElementName elementName,
25722604 elementName ,
25732605 attributes );
25742606 selfClosing = false ;
2607+ // [NOCPP[
2608+ voidElement = true ;
2609+ // ]NOCPP]
25752610 attributes = null ; // CPP
25762611 break starttagloop ;
25772612 default :
@@ -2745,6 +2780,9 @@ public final void startTag(ElementName elementName,
27452780 elementName ,
27462781 attributes );
27472782 selfClosing = false ;
2783+ // [NOCPP[
2784+ voidElement = true ;
2785+ // ]NOCPP]
27482786 pop (); // head
27492787 attributes = null ; // CPP
27502788 break starttagloop ;
@@ -2756,6 +2794,9 @@ public final void startTag(ElementName elementName,
27562794 elementName ,
27572795 attributes );
27582796 selfClosing = false ;
2797+ // [NOCPP[
2798+ voidElement = true ;
2799+ // ]NOCPP]
27592800 pop (); // head
27602801 attributes = null ; // CPP
27612802 break starttagloop ;
@@ -2844,6 +2885,18 @@ public final void startTag(ElementName elementName,
28442885 }
28452886 if (selfClosing ) {
28462887 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]
28472900 }
28482901 // CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) {
28492902 // CPPONLY: Portability.delete(attributes);
0 commit comments