Skip to content
Permalink
Browse files
8247235: doclint should permit "self-closing" tags for void elements …
…in HTML5

Reviewed-by: hannesw
  • Loading branch information
jonathan-gibbons committed Jun 11, 2020
1 parent 52be894 commit e3cb4df4efaabcb1101267993b3dadb1134ae981
Showing 3 changed files with 21 additions and 6 deletions.
@@ -375,7 +375,7 @@ public Void visitStartElement(StartElementTree tree, Void ignore) {
}

// check for self closing tags, such as <a id="name"/>
if (tree.isSelfClosing()) {
if (tree.isSelfClosing() && !isSelfClosingAllowed(t)) {
env.messages.error(HTML, tree, "dc.tag.self.closing", treeName);
}

@@ -415,6 +415,13 @@ public Void visitStartElement(StartElementTree tree, Void ignore) {
}
}

// so-called "self-closing" tags are only permitted in HTML 5, for void elements
// https://html.spec.whatwg.org/multipage/syntax.html#start-tags
private boolean isSelfClosingAllowed(HtmlTag tag) {
return env.htmlVersion == HtmlVersion.HTML5
&& tag.endKind == HtmlTag.EndKind.NONE;
}

private void checkStructure(StartElementTree tree, HtmlTag t) {
Name treeName = tree.getName();
TagStackItem top = tagStack.peek();
@@ -23,7 +23,7 @@

/*
* @test
* @bug 4515705 4804296 4702454 4697036 8025633 8182765
* @bug 4515705 4804296 4702454 4697036 8025633 8182765 8247235
* @summary Make sure that first sentence warning only appears once.
* Make sure that only warnings/errors are printed when quiet is used.
* Make sure that links to private/unincluded methods do not cause
@@ -50,18 +50,24 @@ public void testDefault() {
"pkg");
checkExit(Exit.ERROR);

checkOutput(Output.OUT, true,
checkOutput(Output.OUT, false,
"X.java:23: error: self-closing element not allowed");

checkOutput(Output.OUT, true,
checkOutput(Output.OUT, false,
"X.java:24: error: self-closing element not allowed");

checkOutput(Output.OUT, true,
checkOutput(Output.OUT, false,
"X.java:25: error: self-closing element not allowed");

checkOutput(Output.OUT, true,
checkOutput(Output.OUT, false,
"X.java:26: error: self-closing element not allowed");

checkOutput(Output.OUT, true,
"X.java:28: error: self-closing element not allowed");

checkOutput(Output.OUT, true,
"X.java:28: warning: empty <p> tag");

checkOutput("pkg/X.html", false,
"can't find m()");
checkOutput("pkg/X.html", false,
@@ -24,6 +24,8 @@ private static class P implements Serializable {}
* {@link #m()}<br/>
* {@link #f}<br/>
* {@link java.lang.String#toString()}<br/>
* <hr/>
* <p/>
*/
public void foo() {}
}

0 comments on commit e3cb4df

Please sign in to comment.