Repository navigation
fix(sdk): quote path-variable replacement values in the Spring SDK (#7712) - #7729
Merged
Merged
Conversation
Aias00
approved these changes
Oct 17, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Matcher.quoteReplacement is exactly the right primitive here, and both branches are covered.
Evidence
RegExUtils.replaceAll(url, pattern, replacement)delegates toMatcher.replaceAll, so the replacement is parsed as regex syntax:$1/${name}become group references and\escapes the next character. Quoting only the replacement keeps the pattern untouched, which is why URL matching behaviour is provably unchanged — you pinned that in the PR body and the diff is limited to the replacement argument.- Both the single-string branch (
:55) and theMapbranch (:67) are fixed; leaving one of them unquoted would have kept the same bug for the map form of@PathVariable. - The tests are red-green in the way that matters:
$1throwsIndexOutOfBoundsException: No group 1on the old code, anda\bsilently becomesab, so both new assertions genuinely fail without the fix.
Non-blocking
- I grepped the Spring SDK for other
replaceAll-with-user-value sites and found none, so this closes the class of bug rather than one instance of it. If a future processor adds one, a sharedquoteReplacementhelper would be a better default than remembering to quote. - The tests assert
url.contains("/$1")andurl.contains("/a\\b"); asserting the full construction result (or that no exception is thrown for a value that used to blow up) would be slightly stronger, but this is enough to prevent a regression.
CI: pr_build green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7712.
Summary
PathVariableParameterProcessor#processArgumentpasses the path-variable value directly as the replacement string toRegExUtils.replaceAll. Java replacement syntax interprets$n,${name}and backslashes, so a valid identifier such as$1fails request construction withIndexOutOfBoundsException: No group 1, whilea\bis silently rewritten toab.Modifications
Matcher.quoteReplacement(...)in both the single-string branch and theMap<String, String>branch. The pattern is unchanged, so matching behaviour stays the same; only the user-supplied value is treated literally.Verifying this change
Red-green: with the original unquoted replacement restored, the new tests fail with
IndexOutOfBoundsException: No group 1(the symptom reported in the issue); with the fix, all cases pass.Targeted tests pass:
./mvnw -B -ntp -pl shenyu-sdk/shenyu-sdk-spring test -Dtest=PathVariableParameterProcessorTest16/16 green.
Checkstyle passes:
clean.
Notes
Percent-encoding of path segments is a separate concern and is intentionally not changed here; this PR only stops regex replacement syntax from mangling values.