Skip to content

Fix encoding of MSGID and SD-ID fields of StructuredDataMessage to XML#4136

Merged
vy merged 3 commits into
2.xfrom
fix-StructuredDataMessage-XML-encoding
Jun 5, 2026
Merged

Fix encoding of MSGID and SD-ID fields of StructuredDataMessage to XML#4136
vy merged 3 commits into
2.xfrom
fix-StructuredDataMessage-XML-encoding

Conversation

@vy
Copy link
Copy Markdown
Member

@vy vy commented Jun 1, 2026

No description provided.

@vy vy added this to the 2.27.0 milestone Jun 1, 2026
@vy vy requested review from Copilot and ppkarwasz June 1, 2026 10:34
@vy vy self-assigned this Jun 1, 2026
@vy vy added api Affects the public API layouts Affects one or more Layout plugins labels Jun 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 using StringBuilders.escapeXml(...).
  • Add regression tests covering reserved XML characters, quotes, non-BMP characters, and invalid XML characters in type and id.
  • 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.

Copy link
Copy Markdown
Member

@ppkarwasz ppkarwasz left a comment

Choose a reason for hiding this comment

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

LGTM! 💯

I guess you can not create test cases with control characters forbidden in XML 1.0, because StructuredDataMessage will throw, right?

@vy
Copy link
Copy Markdown
Member Author

vy commented Jun 5, 2026

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.

@vy vy merged commit 6beea3f into 2.x Jun 5, 2026
10 checks passed
@vy vy deleted the fix-StructuredDataMessage-XML-encoding branch June 5, 2026 08:13
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Affects the public API layouts Affects one or more Layout plugins

Projects

Development

Successfully merging this pull request may close these issues.

3 participants