Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micronaut is decoding the ‘+’ in the path variable passed to the controller code #10564

Open
sxsubram opened this issue Mar 1, 2024 · 3 comments · May be fixed by #11513
Open

Micronaut is decoding the ‘+’ in the path variable passed to the controller code #10564

sxsubram opened this issue Mar 1, 2024 · 3 comments · May be fixed by #11513
Assignees
Labels
info: good first issue Good for newcomers type: improvement A minor improvement to an existing feature

Comments

@sxsubram
Copy link

sxsubram commented Mar 1, 2024

Expected Behavior

In my unit test with I have

URI = "/test/1.0/" +
"024-02-07T00:30:48.014+00:00?time=024-02-07T00:30:48.014+00:00"

The controller has
@Get(uris = {“/test/{version}/{+resourcePath}“})

The resourcePath variable and query param should have the raw format value
resource variable path = 024-02-07T00:30:48.014+00:00
query param = 024-02-07T00:30:48.014+00:00
for downstream processing to work.

Actual Behaviour

@Get(uris = {“/test/{version}/{+resourcePath}“})

In my unit test with

URI = "/test/1.0/" +
"024-02-07T00:30:48.014+00:00?time=024-02-07T00:30:48.014+00:00"

client setting unencoded PATH = /test/1.0/024-02-07T00:30:48.014+00:00

resource variable path = 024-02-07T00:30:48.014 00:00 //'+' is replaced with ' '
from http req : path = /test/1.0/024-02-07T00:30:48.014+00:00
from http req : query param time = 024-02-07T00:30:48.014 00:00 //'+' is replaced with ' '

I would like to get the resourcePath and query param in the raw format for downstream processing.

Steps To Reproduce

@Controller
public class HelloController {
    @Get(uris = {"/test/{version}/{+resourcePath}" })
    @Produces(MediaType.ALL)
    public HttpResponse<?> triggerGet(@PathVariable("version") @Nullable String version,
                                      @PathVariable("resourcePath") @Nullable String resourcePath,
                                      HttpRequest httpRequest) {

        String path = httpRequest.getPath(); //This is the actual path
        return HttpResponse.ok("resource variable path = " + resourcePath + "\n" +
                " from http req : path = " + httpRequest.getPath() + "\n" +
                " from http req : query param time = " + httpRequest.getParameters().get("time"));
    }
@Test
    public void testPathUrlUnEncoded() {
        HttpRequest<?> req = HttpRequest.GET("/test/1.0/" +
                "024-02-07T00:30:48.014+00:00?time=024-02-07T00:30:48.014+00:00");
        String path = req.getPath();
        System.out.println("client setting unencoded PATH = " + path + "\n");
        System.out.println(client.toBlocking().retrieve(req));
    }

Environment Information

JDK 17
Mac OS - 13.6.4

Example Application

No response

Version

3.9.4

@sxsubram
Copy link
Author

sxsubram commented Mar 2, 2024

(https://datatracker.ietf.org/doc/html/rfc2396) - Within a path segment, the characters
"/", ";", "=", and "?" are reserved, so + in a path should not be changed

@yawkat yawkat added the info: good first issue Good for newcomers label Mar 7, 2024
@yawkat
Copy link
Member

yawkat commented Mar 7, 2024

not sure we can change the existing behavior, but it seems reasonable to add an api to get the unencoded path component.

@yawkat yawkat added the type: improvement A minor improvement to an existing feature label Mar 7, 2024
@sxsubram
Copy link
Author

Hello @yawkat - Is there an ETA for this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: good first issue Good for newcomers type: improvement A minor improvement to an existing feature
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants