Fix encoding of MSGID and SD-ID fields of StructuredDataMessage to XML#4136
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes XML output generation for StructuredDataMessage by ensuring the <type> (MSGID) and <id> (SD-ID) element contents are properly XML-escaped, preventing malformed XML when these fields contain reserved characters or invalid XML code points.
Changes:
- Escape XML for
StructuredDataMessage’s<type>and<id>fields usingStringBuilders.escapeXml(...). - Add regression tests covering reserved XML characters, quotes, non-BMP characters, and invalid XML characters in
typeandid. - Add a changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/changelog/.2.x.x/fix-StructuredDataMessage-XML-encoding.xml |
Documents the XML encoding fix in the 2.x.x changelog stream. |
log4j-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java |
Escapes <type> and <id> values in XML formatting to produce valid XML. |
log4j-api-test/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java |
Adds tests ensuring type/id XML encoding and invalid character handling are correct. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ppkarwasz
left a comment
There was a problem hiding this comment.
LGTM! 💯
I guess you can not create test cases with control characters forbidden in XML 1.0, because StructuredDataMessage will throw, right?
No, it doesn't, yet. It will start throwing after #4103. |
No description provided.