Zhuoxi2000 opened a new pull request, #908:
URL: https://github.com/apache/flink-agents/pull/908
<!--
* Thank you very much for contributing to Flink Agents.
* Please add the relevant components in the PR title. E.g., [api],
[runtime], [java], [python], [hotfix], etc.
-->
<!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this.
-->
Linked issue: #907
### Purpose of change
<!-- What is the purpose of this change? -->
`LocalPrompt.format` previously applied `String.replace` once per variable.
This meant that substituted values could be interpreted again as placeholders,
making the result dependent on map iteration order and allowing a value such as
`{secret}` to expand into another variable's value.
This change scans the original template once and replaces only placeholders
found in that template. Unknown placeholders are left untouched, and
substituted values are inserted literally rather than processed again.
This also restores parity with Python's `SafeFormatter`, which already
performs substitution in a single pass.
### Tests
<!-- How is this change verified? -->
Added regression tests in both Java and Python covering:
* substituted values are not re-expanded;
* values cannot inject another variable;
* the same behavior through both the string and message formatting paths.
The new Java tests fail on `main` and pass with this change.
Validation:
* `mvn -pl api test`: 276 run, 0 failures, 9 skipped
* Python `api/tests/test_prompt.py`: 10 passed
* `mvn -pl api spotless:check`: clean
* `ruff check`: clean
* `ruff format --check`: clean
### API
<!-- Does this change touches any public APIs? -->
No public API signatures are changed. This only fixes placeholder
substitution behavior for values that themselves contain `{...}` tokens
matching another provided variable. Normal template formatting is unaffected.
### Documentation
<!-- Do not remove this section. Check the proper box only. -->
* [ ] `doc-needed` <!-- Your PR changes impact docs -->
* [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
* [ ] `doc-included` <!-- Your PR already contains the necessary
documentation updates -->
--
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]