[html] Test for a closing tag when determining node positions (#5328)
This commit is contained in:
commit
c73e5cb8b1
@ -19,6 +19,8 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#1860](https://github.com/pmd/pmd/issues/1860): \[ant] Reflective access warnings on java > 9 and java < 17
|
||||
* apex
|
||||
* [#5333](https://github.com/pmd/pmd/issues/5333): \[apex] Token recognition errors for string containing unicode escape sequence
|
||||
* html
|
||||
* [5322](https://github.com/pmd/pmd/issues/5322): \[html] CPD throws exception on when HTML file is missing closing tag
|
||||
* java
|
||||
* [#5293](https://github.com/pmd/pmd/issues/5293): \[java] Deadlock when executing PMD in multiple threads
|
||||
* [#5324](https://github.com/pmd/pmd/issues/5324): \[java] Issue with type inference of nested lambdas
|
||||
|
@ -50,15 +50,14 @@ class LineNumbers {
|
||||
nextIndex = determineLocation((AbstractHtmlNode<?>) child, nextIndex);
|
||||
}
|
||||
|
||||
// autoclosing element, eg <a />
|
||||
boolean isAutoClose = n.getNumChildren() == 0
|
||||
&& n instanceof ASTHtmlElement
|
||||
// nextIndex is up to the closing > at this point
|
||||
&& htmlString.startsWith("/>", nextIndex - 2);
|
||||
// explicitly closing element, eg. </a>
|
||||
boolean hasCloseElement = n instanceof ASTHtmlElement
|
||||
// nextIndex is up to the closing tag at this point
|
||||
&& htmlString.startsWith("</" + n.getXPathNodeName() + ">", nextIndex);
|
||||
|
||||
if (n instanceof ASTHtmlDocument) {
|
||||
nextIndex = htmlString.length();
|
||||
} else if (n instanceof ASTHtmlElement && !isAutoClose) {
|
||||
} else if (n instanceof ASTHtmlElement && hasCloseElement) {
|
||||
nextIndex += 2 + n.getXPathNodeName().length() + 1; // </nodename>
|
||||
} else if (n instanceof ASTHtmlComment) {
|
||||
nextIndex += 4 + 3; // <!-- and -->
|
||||
|
@ -21,4 +21,13 @@ class HtmlCpdLexerTest extends CpdTextComparisonTest {
|
||||
doTest("SimpleHtmlFile");
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidHtml() {
|
||||
doTest("InvalidHtml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void metaTag() {
|
||||
doTest("MetaTag");
|
||||
}
|
||||
}
|
||||
|
7
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/InvalidHtml.html
vendored
Normal file
7
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/InvalidHtml.html
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<!-- missing closing tag for div -->
|
||||
<div class='wrapper'>
|
||||
</body>
|
||||
</html>
|
22
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/InvalidHtml.txt
vendored
Normal file
22
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/InvalidHtml.txt
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[#document] 1 8
|
||||
[#doctype] 1 15
|
||||
[\n] 16 16
|
||||
L2
|
||||
[html] 1 7
|
||||
[\n] 17 17
|
||||
L3
|
||||
[body] 1 7
|
||||
[\n] 7 7
|
||||
L4
|
||||
[#comment] 1 36
|
||||
[\n] 37 37
|
||||
L5
|
||||
[div] 1 22
|
||||
[\n] 22 22
|
||||
L6
|
||||
[\n] 8 8
|
||||
L7
|
||||
[\n] 8 8
|
||||
EOF
|
9
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/MetaTag.html
vendored
Normal file
9
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/MetaTag.html
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- meta tag doesn't have a closing tag and this is valid -->
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
27
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/MetaTag.txt
vendored
Normal file
27
pmd-html/src/test/resources/net/sourceforge/pmd/lang/html/cpd/testdata/MetaTag.txt
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[#document] 1 8
|
||||
[#doctype] 1 15
|
||||
[\n] 16 16
|
||||
L2
|
||||
[html] 1 7
|
||||
[\n] 17 17
|
||||
L3
|
||||
[head] 1 7
|
||||
[\n ] 7 4
|
||||
L4
|
||||
[#comment] 5 66
|
||||
[\n ] 67 4
|
||||
L5
|
||||
[meta] 5 27
|
||||
[\n] 27 27
|
||||
L6
|
||||
[\n] 8 8
|
||||
L7
|
||||
[body] 1 7
|
||||
[\n] 7 7
|
||||
L8
|
||||
[\n] 8 8
|
||||
L9
|
||||
[\n] 8 8
|
||||
EOF
|
Loading…
x
Reference in New Issue
Block a user