sharanggupta opened a new pull request, #4396:
URL: https://github.com/apache/logging-log4j2/pull/4396

   Fixes #4344.
   
   `MessagePatternConverter` maps the `html` option to `HtmlTextRenderer`, but 
both of its `render` methods were empty stubs, so `%m{html}` (and `%msg{html}`, 
`%message{html}`) silently dropped the message. This implements the renderer 
instead of removing the option: it HTML-escapes the message with 
`Transform.escapeHtmlTags`, the escaping `HtmlLayout` already applies to 
messages.
   
   Two choices worth a reviewer's eye:
   
   * The issue offers removing the option as the alternative. I implemented it 
because the fix is small and the option is already wired up; if you would 
rather remove `HtmlTextRenderer` and report the option as unknown, I am happy 
to rework this PR that way.
   * I used `Transform.escapeHtmlTags` rather than `StringBuilders.escapeXml` 
(mentioned in the issue) so that the output matches `HtmlLayout`: an apostrophe 
becomes `'`, while `escapeXml` emits `'`, which HTML 4 does not 
define. The cost is one extra `String` per event, only for users of this option 
(the converter already allocates a working builder per event in this path).
   
   ## Tests
   
   Two cases added to `MessagePatternConverterTest`. Both fail on `2.x` 
(`expected: <Hello> but was: <>`) and pass with this change:
   
   * `testHtmlOptionKeepsPlainMessage`: `Hello` is rendered as `Hello`.
   * `testHtmlOptionEscapesMarkup`: markup in the message parameters is escaped 
(`<`, `>`, `&`, `"`, `'`).
   
   ## Verification
   
   * `MessagePatternConverterTest` (12 tests), the other `core.pattern` tests 
and `HtmlLayoutTest` pass; spotless is green on all modules.
   * I did not run the complete `./mvnw verify` of the whole reactor locally 
and rely on CI for it.
   
   Generative-AI disclosure (ASF guidance): Claude Code (Anthropic) assisted in 
drafting the change, tests and this description; the result was reviewed, the 
new tests were confirmed to fail on `2.x` and pass with the change, and the 
tests and formatting checks above were run before opening this PR.
   
   ## Checklist
   
   * [x] Base your changes on `2.x` branch if you are targeting Log4j 2; use 
`main` otherwise
   * [ ] `./mvnw verify` succeeds: not run for the whole reactor locally, see 
Verification above
   * [x] Non-trivial changes contain an entry file in the 
`src/changelog/.2.x.x` directory
   * [x] Tests are provided (`MessagePatternConverterTest`: 2 new tests)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to