diff --git a/src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java b/src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
index fcd2128e..6c8e7617 100644
--- a/src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
+++ b/src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
@@ -134,6 +134,15 @@ public void setErrorProfile(HashMap errorProfileMap) {
this.errorProfileMap = errorProfileMap;
}
+ /**
+ * Gets the errorProfile.
+ *
+ * @param errorProfile
+ */
+ @Override public HashMap getErrorProfile() {
+ return errorProfileMap;
+ }
+
/**
* Reports on an event based on profile selected.
*
@@ -710,18 +719,6 @@ private boolean isAstralPrivateUse(int c) {
note("xhtml1", "Unquoted attribute value.");
}
- @Override
- protected void noteSelfClosingTag() throws SAXException {
- note("html-strict",
- "Self-closing tag syntax in text/html documents is widely"
- + " discouraged; it’s unnecessary and interacts badly"
- + " with other HTML features (e.g., unquoted attribute"
- + " values). If you’re using a tool that injects"
- + " self-closing tag syntax into all void elements,"
- + " without any option to prevent it from doing so,"
- + " then consider switching to a different tool.");
- }
-
/**
* Sets the transitionHandler.
*
diff --git a/src/nu/validator/htmlparser/impl/Tokenizer.java b/src/nu/validator/htmlparser/impl/Tokenizer.java
index 72d42af9..1fa44b87 100755
--- a/src/nu/validator/htmlparser/impl/Tokenizer.java
+++ b/src/nu/validator/htmlparser/impl/Tokenizer.java
@@ -35,6 +35,8 @@
package nu.validator.htmlparser.impl;
+import java.util.HashMap;
+
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.ext.Locator2;
@@ -686,6 +688,15 @@ public ErrorHandler getErrorHandler() {
return this.errorHandler;
}
+ /**
+ * Gets the errorProfile.
+ *
+ * @param errorProfile
+ */
+ public HashMap getErrorProfile() {
+ return null;
+ }
+
/**
* Sets the commentPolicy.
*
@@ -2292,7 +2303,6 @@ private void ensureBufferSpace(int inputLength) throws SAXException {
* flag of the current tag token. Emit the current
* tag token.
*/
- noteSelfClosingTag();
state = transition(state, emitCurrentTagToken(true, pos), reconsume, pos);
if (shouldSuspend) {
break stateloop;
@@ -7588,9 +7598,6 @@ protected void noteAttributeWithoutValue() throws SAXException {
protected void noteUnquotedAttributeValue() throws SAXException {
}
- protected void noteSelfClosingTag() throws SAXException {
- }
-
/**
* Sets the encodingDeclarationHandler.
*
diff --git a/src/nu/validator/htmlparser/impl/TreeBuilder.java b/src/nu/validator/htmlparser/impl/TreeBuilder.java
index 1f437bf7..967b53f6 100644
--- a/src/nu/validator/htmlparser/impl/TreeBuilder.java
+++ b/src/nu/validator/htmlparser/impl/TreeBuilder.java
@@ -1458,6 +1458,8 @@ public final void startTag(ElementName elementName,
flushCharacters();
// [NOCPP[
+ boolean wasSelfClosing = selfClosing;
+ boolean voidElement = false;
if (errorHandler != null) {
// ID uniqueness
@IdType String id = attributes.getId();
@@ -1580,6 +1582,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TITLE:
@@ -1592,6 +1597,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case SCRIPT:
@@ -1778,6 +1786,9 @@ public final void startTag(ElementName elementName,
attributes,
formPointer);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case FORM:
@@ -2124,6 +2135,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case HR:
@@ -2132,6 +2146,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case IMAGE:
@@ -2145,6 +2162,9 @@ public final void startTag(ElementName elementName,
elementName, attributes,
formPointer);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TEXTAREA:
@@ -2324,6 +2344,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case META:
@@ -2391,6 +2414,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case META:
@@ -2399,6 +2425,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case STYLE:
@@ -2438,6 +2467,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
@@ -2572,6 +2604,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
attributes = null; // CPP
break starttagloop;
default:
@@ -2745,6 +2780,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
pop(); // head
attributes = null; // CPP
break starttagloop;
@@ -2756,6 +2794,9 @@ public final void startTag(ElementName elementName,
elementName,
attributes);
selfClosing = false;
+ // [NOCPP[
+ voidElement = true;
+ // ]NOCPP]
pop(); // head
attributes = null; // CPP
break starttagloop;
@@ -2844,6 +2885,18 @@ public final void startTag(ElementName elementName,
}
if (selfClosing) {
errSelfClosing();
+ // [NOCPP[
+ } else if (wasSelfClosing && voidElement
+ && tokenizer.getErrorProfile() != null
+ && tokenizer.getErrorProfile().get("html-strict") != null) {
+ warn("Self-closing tag syntax in text/html documents is widely"
+ + " discouraged; it’s unnecessary and interacts badly"
+ + " with other HTML features (e.g., unquoted attribute"
+ + " values). If you’re using a tool that injects"
+ + " self-closing tag syntax into all void elements,"
+ + " without any option to prevent it from doing so,"
+ + " then consider switching to a different tool.");
+ // ]NOCPP]
}
// CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) {
// CPPONLY: Portability.delete(attributes);