Fix RequestValidator URL encoding preservation during port manipulation #901
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.
The
RequestValidator.validate
method was incorrectly decoding URL-encoded characters when manipulating ports, causing validation failures for URLs with encoded query parameters, paths, or user info.Problem
When validating URLs with ports, the
updatePort
method was using decoded URI components (getPath()
,getQuery()
,getFragment()
,getUserInfo()
), which automatically decoded URL-encoded characters. This caused URLs like:to be incorrectly converted to:
This resulted in different signature validation for equivalent URLs with and without explicit ports.
Solution
Updated the
updatePort
method to use raw URI components that preserve original encoding:getUserInfo()
→getRawUserInfo()
getPath()
→getRawPath()
getQuery()
→getRawQuery()
getFragment()
→getRawFragment()
The method now manually constructs URLs using a
StringBuilder
to avoid the automatic encoding performed by theURI
constructor.Testing
testValidatePreservesUrlEncodingInQuery
to prevent regressionExample that now works correctly:
Fixes #601.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.