quarkiverse / quarkus-renarde

Server-side Web Framework with Qute templating, magic/easier controllers, auth, reverse-routing
Apache License 2.0
78 stars 19 forks source link

Incorrect URL Encoding for Optional Parameters #151

Closed gbourant closed 1 year ago

gbourant commented 1 year ago

Hi there,

I hope you're doing well. I encountered an issue while using the quarkus-renarde project. When binding Optional parameters and performing a redirect, the URL encoding for the Optional values seems to be incorrect, resulting in unexpected behavior.

Steps to Reproduce:

  1. Define a method with Optional parameters like this:
public TemplateInstance shops(@RestQuery(value = "id") Optional<Long> optionalId, @RestQuery(value = "page") Optional<Integer> optionalPageNumber) {
  // Method implementation...
}
  1. Call the shops method from another method for a redirect:
    return this.shops(Optional.of(shop.id), Optional.empty());

The URL is generated incorrectly, and the Optional values are not properly encoded, leading to URLs like:

http://localhost:8080/admin/shops?id=Optional%5B501%5D&page=Optional.empty

where %5B and %5D represent [ and ], respectively, and 501 is the id of the shop.

Thank you.

FroMage commented 1 year ago

Ah, indeed I don't think we handle Optional at all. We need to fix this.

gbourant commented 1 year ago

Also when attempting to inject a URI with {uriabs:AdminShopResource.shopsNew(it.id)} into a Qute template while the parameter is an Optional one the following error is encountered:

java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.util.Optional

FroMage commented 1 year ago

Fixed, thanks for reporting!