Prioritize RawPath to Avoid Encoding Issues in URLs #104
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.
Description:
This pull request addresses an encoding issue when processing URLs. We have modified the URL retrieval mechanism to first check the
RawPath
of the request, and if it's empty, to then check thePath
. This change prioritizes the original, escaped form of the URL (RawPath
) over the decoded form (Path
) to avoid potential encoding issues and ambiguities.Motivation:
Previously, requests to unregistered routes like
GET /v1/%a1
would generate a panic with the message:label value \"/v1/\\xa1\" is not valid UTF-8
. This is due to the fact that when decoding%a1
, it results in a byte sequence that's not valid UTF-8. By checkingRawPath
first, we are ensuring that the original encoding of the URL is preserved, thereby avoiding such issues.Changes:
RawPath
overPath
.Testing:
Ensure that the application no longer panics when sending requests to unregistered routes containing non-UTF-8 encoded characters, like
GET /v1/%a1
.Note:
The implemented change references Go's URL handling mechanism as described in this documentation.