micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

Allowing reserved characters in a path variables makes '+' decode as a space

Open Iman78 opened this issue 3 years ago • 1 comments

Expected Behavior

To support '+' in the path portion of the url, I'm using https://www.rfc-editor.org/rfc/rfc6570#section-3.2.3 to allow reserved characters like so:

  @Get("{+variable}")
  public HttpResponse<Object> method(@PathVariable("variable") String variable) {
      ...
  }

From this test I understand that f I call my GET endpoint with /tes+t, I should expect the value of variable to be tes+t.

Actual Behaviour

Instead I get tes t. The plus sign is decoded as a space, which seems to be due to the use of java.net.URLDecoder in DefaultUriRouteMatch. If you think this behavior should remain, then it'd be very helpful to have a configuration to opt-out of it.

Steps To Reproduce

  1. Any project with an http server.
  2. Add an endpoint that has a path variable allowing reserved characters: @Get("{+variable}")
  3. Send a request to said endpoint with a value containing the plus sign.
  4. Inspect the value of the variable inside to annotated method, it should have a space instead of the plus sign.

Environment Information

OS: MacOS Catalina JDK 11

Example Application

No response

Version

3.6.0

Iman78 avatar Sep 28 '22 09:09 Iman78

Can you please confirm that this is still an issue in the latest version of Micronaut?

ojebari-ma avatar May 26 '25 01:05 ojebari-ma

Hi,

Not sure if it is completely related with the current issue but in micronaut 4.9.x, the following is happening.

With a client like below:

@Client
public interface MyClient {
  @Get("/test/{rest}")
  HttpResponse<@NotNull String> test(@PathVariable("rest") @NotNull String rest);
}

A call like:

myClient.test("this/will/be/encoded")

Leads to:

GET /test/this%2Fwill%2Fbe%2Fencoded

While the expected is:

GET /test/this/will/be/encoded

It would be nice if not encoding could be passed on to the client.

Thanks!

mohamedif avatar Jul 02 '25 12:07 mohamedif