Repository navigation
Closed
Description
Affects PMD Version:
7.7.0
Make sure, to test with the latest PMD version.
Description:
I have the following code replicated into two files file1.html and file2.html in my directory: see code sample below.
But if I use CPD with HTML, it never includes the last line in my results.
That is
</html>
Specifically, if I use the cpd-gui with:
Report duplicate chunks larger than: 100
and
Language: HTML
then it gives back:
Found a 43 line (123 tokens) duplication in the following files:
Starting at line 1 of /temp/file1.html
Starting at line 1 of /temp/file2.html
<html>
<body>
<div>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>hurray</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>okay</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
</div>
</body>
I would expect it give back 44 lines instead of 43 so that it includes the last line.
Code Sample demonstrating the issue:
<html>
<body>
<div>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>hurray</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>okay</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
<a>This file lives in the parent folder</a>
<a>And it lives in the sub folder</a>
</div>
</body>
</html>
Activity
[-]CPD gets end line wrong for HTML[/-][+][html] CPD gets end line wrong for HTML[/+]UncleOwen commentedon May 18, 2026
I can reproduce this, in both 7.7.0 and 7.24.0 - but only, if at least one of the files does not end in a newline. Which every textfile should. But still, I think CPD should be able to handle this.
[html] Fix pmd#5313: CPD end line without trailing newline (pmd#7050)
[-][html] CPD gets end line wrong for HTML[/-][+][html] CPD does not include last line in duplication chunk[/+][-][html] CPD does not include last line in duplication chunk[/-][+][html] CPD does not include the last line in the duplication chunk[/+]