Escape file name in checkstyle report output - #117
Open
ralucaStan wants to merge 1 commit into
Open
Conversation
CheckstyleReporter escaped the message and source attributes but
interpolated the file name into the <file name="..."> element raw. A
path containing an XML metacharacter (", <, >, &) produced malformed
checkstyle XML, which downstream consumers such as cs2pr then fail to
parse. Escape the file name with the same escapeXml helper already used
for the other attributes, and cover it with a test.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CheckstyleReporterescapes themessageandsourceattributes but interpolates the file name into the<file name="...">element raw. A path that contains an XML metacharacter (",<,>,&) therefore produces malformed checkstyle XML.Impact
Any consumer that parses the checkstyle report — for example
cs2pr, which turns it into GitHub PR annotations — fails to parse the output, so that run's findings silently don't render. File names come from the diff being linted, so this triggers whenever a changed file's path contains one of those characters. (The checkstyle reporter was added in #108.)Fix
Escape the file name with the same
escapeXmlhelper already used for the other attributes, and add a regression test (testXmlEscapingInFilename)../vendor/bin/phpunitandcomposer lintpass.Note
XmlReporterinterpolates the file name (and itsmessage/source) the same way; I've kept this PR scoped to the checkstyle format and am happy to follow up on the XML reporter separately if you'd like.Prepared with AI assistance (Claude).