CCCLL opened a new pull request, #16560:
URL: https://github.com/apache/dubbo/pull/16560

   ## What is the purpose of the change?
   
   Fixes #16559.
   
   Triple REST decoded path and matrix variables with `RequestUtils.decodeURL`, 
which is `URLDecoder.decode`, a decoder for form data that turns `+` into a 
space. In a URL path `+` is an ordinary character (RFC 3986, section 3.3), so 
`GET /users/[email protected]` passed `john [email protected]` to a 
`@Param(type = PathVariable)`, Spring `@PathVariable` or JAX-RS `@PathParam` 
parameter. Spring MVC, RESTEasy and `java.net.URI` keep the `+`.
   
   This PR adds `RequestUtils.decodePath`, which turns a raw `+` into `%2B` and 
then calls `decodeURL`, so well-formed percent escapes decode as before and a 
`+` stays a `+`. It is used where the value comes from the path: 
`RequestUtils.getPathVariable`, `RequestUtils.parseMatrixVariables`, and the 
path variable resolvers of the basic, Spring and JAX-RS styles. `decodeURL` 
itself and its other caller (`GeneralTypeConverter`) are unchanged.
   
   ## Behavior change
   
   - A raw `+` in a path or matrix variable now reaches the method as `+` 
instead of a space. `%20` still decodes to a space and `%2B` to `+`.
   - A client that encoded spaces in a path segment as `+` (for example with 
`URLEncoder`) now gets a `+`. It has to send `%20`, as it already must for 
Spring MVC and JAX-RS servers.
   - Query parameters, form bodies and JAX-RS `@Encoded` parameters are not 
affected.
   
   If you would rather keep the old decoding available, I can add a 
`RestConfig` option for it.
   
   ## Not covered
   
   - `@GRequest` copies the path variables into the bound object without 
decoding them at all (`GRequestArgumentResolver`).
   - Values converted to a `Map` are decoded a second time with `decodeURL` in 
`GeneralTypeConverter` (query parameters as well), and the OpenAPI handlers 
decode their `{*path}` resource path twice. Both are left as they are.
   
   ## Verification
   
   - New tests: "path variable test" in `RestProtocolTest` of dubbo-rpc-triple 
(`@Param`) and dubbo-rest-spring (`@PathVariable`), "path param test" in 
dubbo-rest-jaxrs (`@PathParam`), and `RequestUtilsTest` for `getPathVariable` 
and `parseMatrixVariables`. The `+` cases fail before the change (`john( 
)[email protected]` instead of `john(+)[email protected]`) and pass after it; the 
`%20` cases pass before and after.
   - Switching any one of the five call sites back to `decodeURL`, or dropping 
the `+` handling from `decodePath`, makes at least one of these tests fail.
   - Compared `RequestUtils.decodePath` with Spring `UriUtils.decode`, RESTEasy 
3.15.6 `Encode.decodePath` and `java.net.URI#getPath()` on the same 153 path 
segments as in the issue: no differences (`decodeURL` differs on the 7 segments 
with a raw `+`).
   - `mvn clean test verify` of dubbo-rpc-triple, dubbo-rest-spring and 
dubbo-rest-jaxrs with the options of the CI unit test job, on JDK 8, 11, 17, 21 
and 25: 592 tests, 0 failures each time (35 skipped, existing `@Disabled` 
tests); checkstyle and spotless are clean. dubbo-rest-openapi, which calls 
`getPathVariable`, compiles and has no tests.
   - End to end, one provider exporting the three styles, requested with 
`HttpURLConnection`:
   
   | Request | 3.3.0 and 3.3.6 | this PR |
   |---|---|---|
   | `/basic/users/[email protected]` | `john [email protected]` | 
`[email protected]` |
   | `/spring/users/[email protected]` | `john [email protected]` | 
`[email protected]` |
   | `/jaxrs/users/[email protected]` | `john [email protected]` | 
`[email protected]` |
   | `/basic/matrix/x;tag=1.0+build` | `1.0 build` | `1.0+build` |
   | `/basic/users/a%2Bb` | `a+b` | `a+b` |
   
   ## Checklist
   - [x] Make sure there is a 
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Write necessary unit-test to verify your logic correction. If the new 
feature or significant change is committed, please remember to add sample in 
[dubbo samples](https://github.com/apache/dubbo-samples) project.
   - [ ] Make sure gitHub actions can pass. [Why the workflow is failing and 
how to fix it?](../CONTRIBUTING.md)
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to