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

   Fixes #2679.
   
   `StrSubstitutor` closed a `${...}` expression at the first unmatched `}` and 
offered no way to escape it, so a default value containing braces (e.g. 
`${env:TZ:-%d{yyyy-MM-dd HH:mm:ss}{GMT+00}}`) was cut short and left a trailing 
`}` behind.
   
   As agreed in #2679, the escape character `$` now also escapes a following 
`$`, `:`, `-` or `}` inside an expression, and the escaped character loses its 
special meaning:
   
   * `${foo:-%d{HH:mm:ss$}{GMT+00$}}` expands to `%d{HH:mm:ss}{GMT+00}` when 
`foo` is undefined,
   * `${sys$:-foo}` and `${sys:$-foo}` resolve the system property `-foo`,
   * `${foo:-$$}` expands to `$`.
   
   `$` before any other character, `$${` at the top level, `:\-` and nested 
lookups behave as before. The class Javadoc and the "Property substitution" 
note in `configuration.adoc` document the new rule.
   
   Behaviour changes worth a reviewer's eye, inherent to the agreed design: 
inside `${...}` the pairs `$$`, `$:`, `$-` and `$}` now collapse to one 
character, so a key or default that literally contained them changes meaning (a 
default ending in `$` now needs `$$`). Likewise `$${bar}` inside an expression 
is now a literal `${bar` followed by the closing `}`; the common 
deferred-lookup default `${env:X:-$${ctx:k}}` still yields `${ctx:k}`, and 
`$${bar$}` restores the old reading where needed.
   
   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 
build and lint goals were run before opening this PR.
   
   ## Checklist
   
   * [x] Base your changes on `2.x` branch if you are targeting Log4j 2; use 
`main` otherwise
   * [x] `./mvnw verify` succeeds (`-pl log4j-core verify -DskipTests` incl. 
spotless, plus the `*Substitutor*`, `*Lookup*`, `*Interpolator*` tests in 
`log4j-core-test`: 106 tests green)
   * [x] Non-trivial changes contain an entry file in the 
`src/changelog/.2.x.x` directory
   * [x] Tests are provided (`StrSubstitutorTest`: 6 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