Repository navigation
Keep a '$' that does not start a placeholder intact in StringPropertyReplacer - #55327
Conversation
4dba8fc to
57dec6d
Compare
|
@payallenka - thank you for your pull request. I pushed some changes to your PR. Please let me know if this works for you in your Keycloak setup. As stated in the comment on the issue, I tried to minimize the change so we can backport it without a risk to break existing user's setup. |
hanks @ahus1, that makes sense: keeping $${...} as-is avoids breaking existing setups, and the escape question fits better in #55355. I tested your version locally and the common module tests pass. Marking it ready for review. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the literal-dollar handling fix in StringPropertyReplacer.
No open issues 🎉
What changed in this PR
Fixes literal $ handling in StringPropertyReplacer, used for template substitution across Keycloak configuration and messages.
Changes:
- Prevents trailing
$characters from producing invalid output and allows placeholders ending in$to close correctly. - Adds regression tests while preserving existing behavior for
$directly before a placeholder. - Documents the fixes, unchanged behavior, and escape-syntax limitations.
| File | Description |
|---|---|
| docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc | Documents corrected literal-dollar handling and remaining limitations. |
| common/src/test/java/org/keycloak/common/util/StringPropertyReplacerTest.java | Tests trailing dollars, closing braces, and existing adjacent-placeholder behavior. |
| common/src/main/java/org/keycloak/common/util/StringPropertyReplacer.java | Handles end-of-input safely and reprocesses closing-brace look-ahead. |
Review effort: Balanced
…Replacer
A '$' not followed by '{' was pushed back together with the look-ahead
character as raw bytes. At the end of the input the look-ahead -1 became
the byte 0xFF, a '$' right before a placeholder kept it from being
replaced, and a '$' right before a closing brace kept the placeholder from
being closed. The look-ahead character is now processed normally on the
next read.
Closes keycloak#55326
Signed-off-by: Payal Lenka <payalm.lenka@gmail.com>
Closes keycloak#55326 Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
57dec6d to
4c7a019
Compare
Closes #55326
When
StringPropertyReplacerreads a$that is not followed by{, it pushed the$and the look-ahead character back as raw bytes. The look-ahead then skipped all further processing: at the end of the input-1was written as the byte0xFF(a stray U+FFFD), a$right before a placeholder ($${b}) prevented the replacement, and a$right before a closing brace (${x:5$}) left the placeholder unclosed.The look-ahead character is now kept and processed by the next
read()like any other character, so it can be the end of the input, the closing brace of the current key or the start of another placeholder. Inputs without a stray$are unaffected.StringPropertyReplacerTest.testDollarSignNotStartingPlaceholdercovers the three cases; it fails on main and the wholecommonmodule passes with the change.I used an AI coding assistant (Claude) to help find the bug and write the fix and test. I reviewed and tested the change myself and will handle the review.