Skip to content

Commit

Permalink
8292157: Incorrect error: "block element not allowed within inline el…
Browse files Browse the repository at this point in the history
…ement <a>"

Reviewed-by: jjg
  • Loading branch information
hns committed Jun 6, 2023
1 parent 16ab7bf commit 0a4f9ad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,21 @@ private void checkStructure(StartElementTree tree, HtmlTag t) {
case START_ELEMENT -> {
if (top.tag.blockType == HtmlTag.BlockType.INLINE) {
Name name = ((StartElementTree) top.tree).getName();
env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.element",
treeName, name);
// Links may use block display style so issue warning instead of error
if ("a".equalsIgnoreCase(name.toString())) {
env.messages.warning(HTML, tree, "dc.tag.not.allowed.element.default.style",
treeName, name);
} else {
env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.element",
treeName, name);
}
return;
}
}

case LINK, LINK_PLAIN -> {
String name = top.tree.getKind().tagName;
env.messages.error(HTML, tree, "dc.tag.not.allowed.inline.tag",
env.messages.warning(HTML, tree, "dc.tag.not.allowed.tag.default.style",
treeName, name);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ dc.tag.nested.tag=nested tag: {0}
dc.tag.not.allowed.here = tag not allowed here: <{0}>
dc.tag.not.allowed = element not allowed in documentation comments: <{0}>
dc.tag.not.allowed.inline.element = block element not allowed within inline element <{1}>: {0}
dc.tag.not.allowed.inline.tag = block element not allowed within @{1}: {0}
dc.tag.not.allowed.inline.other = block element not allowed here: {0}
dc.tag.not.allowed.element.default.style = block element <{0}> not allowed within element <{1}> with default style
dc.tag.not.allowed.tag.default.style = block element <{0}> not allowed within @{1} with default style
dc.tag.not.closed= element not closed: {0}
dc.tag.p.in.pre= unexpected use of <p> inside <pre> element
dc.tag.requires.heading = heading not found for </{0}>
Expand Down
3 changes: 2 additions & 1 deletion test/langtools/tools/doclint/HtmlTagsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8004832 8247957
* @bug 8004832 8247957 8292157
* @summary Add new doclint package
* @modules jdk.javadoc/jdk.javadoc.internal.doclint
* @build DocLintTester
Expand Down Expand Up @@ -32,6 +32,7 @@ public void not_allowed() { }

/**
* <span> <p> </span>
* <a> <p> </a>
*/
public void not_allowed_inline() { }

Expand Down
30 changes: 18 additions & 12 deletions test/langtools/tools/doclint/HtmlTagsTest.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,41 @@ HtmlTagsTest.java:34: error: block element not allowed within inline element <sp
HtmlTagsTest.java:34: warning: empty <p> tag
* <span> <p> </span>
^
HtmlTagsTest.java:39: error: block element not allowed within @link: p
HtmlTagsTest.java:35: warning: block element <p> not allowed within element <a> with default style
* <a> <p> </a>
^
HtmlTagsTest.java:35: warning: empty <p> tag
* <a> <p> </a>
^
HtmlTagsTest.java:40: warning: block element <p> not allowed within @link with default style
* {@link java.lang.String <p> }
^
HtmlTagsTest.java:40: error: block element not allowed within @link: p
HtmlTagsTest.java:41: warning: block element <p> not allowed within @link with default style
* {@link java.lang.String <p> }
^
HtmlTagsTest.java:45: error: invalid end tag: </img>
HtmlTagsTest.java:46: error: invalid end tag: </img>
* <img src="any.jpg" alt="alt"> </img>
^
HtmlTagsTest.java:50: error: end tag missing: </b>
HtmlTagsTest.java:51: error: end tag missing: </b>
* <i> <b> </i>
^
HtmlTagsTest.java:55: error: unexpected end tag: </b>
HtmlTagsTest.java:56: error: unexpected end tag: </b>
* <i> </b> </i>
^
HtmlTagsTest.java:55: warning: empty <i> tag
HtmlTagsTest.java:56: warning: empty <i> tag
* <i> </b> </i>
^
HtmlTagsTest.java:60: error: text not allowed in <ul> element
HtmlTagsTest.java:61: error: text not allowed in <ul> element
* <ul> text <li> ... </li> </ul>
^
HtmlTagsTest.java:65: error: tag not allowed here: <b>
HtmlTagsTest.java:66: error: tag not allowed here: <b>
* <ul> <b>text</b> <li> ... </li> </ul>
^
HtmlTagsTest.java:70: error: text not allowed in <ul> element
HtmlTagsTest.java:71: error: text not allowed in <ul> element
* <ul> &amp; <li> ... </li> </ul>
^
HtmlTagsTest.java:75: error: text not allowed in <ul> element
HtmlTagsTest.java:76: error: text not allowed in <ul> element
* <ul> *@/ <li> ... </li> </ul>
^
15 errors
2 warnings
13 errors
6 warnings

1 comment on commit 0a4f9ad

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.