Skip to content

[html] CPD does not include the last line in the duplication chunk #5313

Closed

Description

@stephen-carter-at-sf

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

  1. added
    a:bug
    on Nov 7, 2024
  2. added
    in:cpd
    on Nov 7, 2024
  3. changed the title [-]CPD gets end line wrong for HTML[/-] [+][html] CPD gets end line wrong for HTML[/+] on Nov 13, 2024
  4. UncleOwen commented on May 18, 2026

    @UncleOwen
    Member

    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.

  5. added this to the 7.29.0 milestone on Oct 7, 2026
  6. added a commit that references this issue on Oct 8, 2026
    8871b62
  7. changed the title [-][html] CPD gets end line wrong for HTML[/-] [+][html] CPD does not include last line in duplication chunk[/+] on Oct 29, 2026
  8. changed the title [-][html] CPD does not include last line in duplication chunk[/-] [+][html] CPD does not include the last line in the duplication chunk[/+] on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugin:cpd

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions