fix character escaping in checkstyle formatter#1104
Merged
m-ildefons merged 3 commits intohadolint:masterfrom Aug 15, 2025
Merged
fix character escaping in checkstyle formatter#1104m-ildefons merged 3 commits intohadolint:masterfrom
m-ildefons merged 3 commits intohadolint:masterfrom
Conversation
Fix special character escaping in checkstyle formatter. The checkstyle formatter produces an XML document, where only `<`, `>`, `&`, `'` and `"` need to be escaped. related-to: hadolint#1065 Signed-off-by: Moritz Röhrich <moritz@ildefons.de>
Member
Author
|
@rantoniuk would this fix your issue? |
|
I didn't test it (as I would need to manually pull the related GH action, build it, publish it and then update my repository to use that custom image), but from your before/after description it looks okay. |
rantoniuk
reviewed
Aug 8, 2025
src/Hadolint/Formatter/Checkstyle.hs
Outdated
| then Text.singleton c | ||
| else "&#" <> Text.pack (show (ord c)) <> ";" | ||
| isOk x = any (\check -> check x) [isAsciiUpper, isAsciiLower, isDigit, (`elem` [' ', '.', '/'])] | ||
| else xmlEscape c |
There was a problem hiding this comment.
Maybe you'd like to use one of the libraries instead?
Member
Author
There was a problem hiding this comment.
That's probably overall the best way to go.
I had thought about it but wasn't quite sure which library was best to choose.
I've now decided to go with xml-conduit. It was a quite a bit of work to move the code over, but I'm happy as there is now overall less code and the bits that are there seem less fragile to me.
Use xml-conduit to do XML document generation in the checkstyle formatter. Using a library with robust encoding routines ensures less problems, e.g. with escaped characters. Signed-off-by: Moritz Röhrich <moritz@ildefons.de>
Signed-off-by: Moritz Röhrich <moritz@ildefons.de>
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.
Fix special character escaping in checkstyle formatter. The checkstyle formatter produces an XML document, where only
<,>,&,'and"need to be escaped.related-to: #1065
What I did
Fix special character escaping to match XML 1.0 expectation: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Standard_public_entity_sets_for_characters
How to verify it
Previous to this change:
After this change: