Skip to content

Keep a '$' that does not start a placeholder intact in StringPropertyReplacer - #55327

Merged
ahus1 merged 2 commits into
keycloak:mainfrom
payallenka:replacer-lone-dollar
Nov 19, 2026
Merged

ahus1 merged 2 commits into
keycloak:mainfrom
payallenka:replacer-lone-dollar

Conversation

@payallenka

Copy link
Copy Markdown
Contributor

Closes #55326

When StringPropertyReplacer reads 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 -1 was written as the byte 0xFF (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.testDollarSignNotStartingPlaceholder covers the three cases; it fails on main and the whole common module 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.

@ahus1

ahus1 commented Nov 19, 2026

Copy link
Copy Markdown
Member

@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.

@ahus1 ahus1 self-assigned this Nov 19, 2026
@payallenka

Copy link
Copy Markdown
Contributor Author

@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.

@ahus1
ahus1 marked this pull request as ready for review November 19, 2026 20:46
@ahus1
ahus1 requested a review from a team as a code owner November 19, 2026 20:46
Copilot AI balanced review requested due to automatic review settings November 19, 2026 20:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

payallenka and others added 2 commits November 19, 2026 21:59
…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>
@ahus1
ahus1 force-pushed the replacer-lone-dollar branch from 57dec6d to 4c7a019 Compare November 19, 2026 21:00
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ahus1
ahus1 enabled auto-merge (squash) November 19, 2026 21:04
@ahus1
ahus1 merged commit 994ee7e into keycloak:main Nov 19, 2026
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A $ that does not start a placeholder is corrupted by StringPropertyReplacer

3 participants