echo-contrib icon indicating copy to clipboard operation
echo-contrib copied to clipboard

Prioritize RawPath to Avoid Encoding Issues in URLs

Open d6o opened this issue 2 years ago • 0 comments

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 the Path. 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 checking RawPath first, we are ensuring that the original encoding of the URL is preserved, thereby avoiding such issues.

Changes:

  • Updated the URL retrieval logic to prioritize RawPath over Path.
  • Added relevant comments with references to the Go documentation for clarity.

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.

d6o avatar Oct 18 '23 14:10 d6o