Skip to content

[html] Fix #6135: HtmlCpdLexer giving IndexOutOfBoundsException when script contains unescaped closing tag - #7028

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
lukasgraef:issue6135
Sep 9, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
lukasgraef:issue6135

Conversation

@lukasgraef

@lukasgraef lukasgraef commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Describe the PR

A workaround for handling the index lookup for Jsoup's synthetic comment nodes. These nodes are added on malformed input, but not backed by the actual html text. Our Jsoup parser uses Parser.xmlParser(), so it chokes on inputs like </: inside a script tag.

The proper solution would probably be to use Parser.htmlParser(), but as noted in this comment, that would break too much behaviour.

Maybe switching to htmlParser would be another good item for #5703?

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

…en script contains unescaped closing tag
@pmd-actions-helper

pmd-actions-helper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-09-09 08:53:17+00:00 for e8656f7)

@lukasgraef
lukasgraef marked this pull request as ready for review September 4, 2026 08:00
@lukasgraef
lukasgraef marked this pull request as draft September 4, 2026 13:00
@lukasgraef
lukasgraef marked this pull request as ready for review September 5, 2026 14:44
This way handling of start and end of comments is symmetrical and close together.
# Conflicts:
#	docs/pages/release_notes.md
@UncleOwen

Copy link
Copy Markdown
Member

I've created #7053 for the potential switch to Parser.htmlParser()

@UncleOwen UncleOwen added this to the 7.28.0 milestone Sep 9, 2026

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@UncleOwen
UncleOwen merged commit 9ade26b into pmd:main Sep 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[html] HtmlCpdLexer giving IndexOutOfBoundsException when script contains unescaped closing tag

2 participants