Skip to content

Commit

Permalink
Collect stats on <style> in <body>
Browse files Browse the repository at this point in the history
Relates to whatwg/html#1605
  • Loading branch information
sideshowbarker authored and tripu committed Aug 19, 2016
1 parent c10de32 commit 99b09f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/nu/validator/servlet/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public enum Field {
"XHTML output"), OUTPUT_XML("XML output"), OUTPUT_JSON(
"JSON output"), OUTPUT_GNU("GNU output"), OUTPUT_TEXT(
"Text output"), INPUT_HTML("HTML input"), INPUT_XML("XML input"),
STYLE_IN_BODY_FOUND("<style> in <body> found"),
LANG_FOUND("<html lang> found"),
LANG_WRONG("<html lang> does not match detected language"),
LANG_EMPTY("<html lang>: empty (lang=\"\")"),
Expand Down
6 changes: 6 additions & 0 deletions src/nu/validator/servlet/VerifierServletTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,12 @@ private void gatherStatistics() {
} else if (externalSchematron) {
stats.incrementField(Statistics.Field.LOGIC_ERROR);
}
if (request.getAttribute(
"http://validator.nu/properties/style-in-body-found") != null
&& (boolean) request.getAttribute(
"http://validator.nu/properties/style-in-body-found")) {
stats.incrementField(Statistics.Field.STYLE_IN_BODY_FOUND);
}
if (request.getAttribute(
"http://validator.nu/properties/lang-found") != null
&& (boolean) request.getAttribute(
Expand Down
9 changes: 9 additions & 0 deletions src/nu/validator/xml/LanguageDetectingXMLReaderWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public void endElement(String uri, String localName, String qName)
documentContent.append(elementContent);
elementContent.setLength(0);
}
if ("body".equals(localName)) {
inBody = true;
}
contentHandler.endElement(uri, localName, qName);
}

Expand Down Expand Up @@ -231,6 +234,12 @@ public void startElement(String uri, String localName, String qName,
dirAttrValue = atts.getValue(i);
}
}
} else if ("style".equals(localName)) {
if (inBody && request != null) {
request.setAttribute(
"http://validator.nu/properties/style-in-body-found",
true);
}
} else if ("body".equals(localName)) {
inBody = true;
}
Expand Down

0 comments on commit 99b09f0

Please sign in to comment.