Skip to content

Commit b2805f5

Browse files
Warn about self-closing tag syntax if profile is “html-strict” (#73)
1 parent 1d1f95a commit b2805f5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,18 @@ private boolean isAstralPrivateUse(int c) {
710710
note("xhtml1", "Unquoted attribute value.");
711711
}
712712

713+
@Override
714+
protected void noteSelfClosingTag() throws SAXException {
715+
note("html-strict",
716+
"Self-closing tag syntax in text/html documents is widely"
717+
+ " discouraged; it’s unnecessary and interacts badly"
718+
+ " with other HTML features (e.g., unquoted attribute"
719+
+ " values). If you’re using a tool that injects"
720+
+ " self-closing tag syntax into all void elements,"
721+
+ " without any option to prevent it from doing so,"
722+
+ " then consider switching to a different tool.");
723+
}
724+
713725
/**
714726
* Sets the transitionHandler.
715727
*

src/nu/validator/htmlparser/impl/Tokenizer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,7 @@ private void ensureBufferSpace(int inputLength) throws SAXException {
22922292
* flag of the current tag token. Emit the current
22932293
* tag token.
22942294
*/
2295+
noteSelfClosingTag();
22952296
state = transition(state, emitCurrentTagToken(true, pos), reconsume, pos);
22962297
if (shouldSuspend) {
22972298
break stateloop;
@@ -7587,6 +7588,9 @@ protected void noteAttributeWithoutValue() throws SAXException {
75877588
protected void noteUnquotedAttributeValue() throws SAXException {
75887589
}
75897590

7591+
protected void noteSelfClosingTag() throws SAXException {
7592+
}
7593+
75907594
/**
75917595
* Sets the encodingDeclarationHandler.
75927596
*

0 commit comments

Comments
 (0)