Skip to content

Commit

Permalink
Do not append single '&' with empty query params in Resteasy Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Feb 28, 2023
1 parent 042a965 commit de389aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ public void testInjection() {
Assertions.assertEquals("%FF,{foo&bar}", data);
}

@Test
public void testEmptyQueryParam() {
Object data = client.target(url.toExternalForm() + "/absoluteURI")
// Empty query param should be omitted in the generated URI
.queryParam("empty")
.queryParam("param", "a")
.request()
.rx(UniInvoker.class)
.get()
.await()
.indefinitely();
Assertions.assertEquals("http://localhost:8081//absoluteURI?param=a", data);
}

public static class Endpoint {

public void setup(@Observes Router router) {
Expand All @@ -68,6 +82,12 @@ public void handle(RoutingContext event) {
.collect(Collectors.joining(",")));
}
});
router.route("/absoluteURI").handler(new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext event) {
event.response().end(event.request().absoluteURI());
}
});
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ public WebTargetImpl queryParam(String name, Object... values) throws NullPointe
UriBuilder copy = uriBuilder.clone();
if (copy instanceof UriBuilderImpl) {
var impl = (UriBuilderImpl) copy;
if (values == null || (values.length == 1 && values[0] == null)) {
if (values == null || values.length == 0 || (values.length == 1 && values[0] == null)) {
impl.replaceQueryParam(name, (Object[]) null);
} else {
String[] stringValues = toStringValues(values);
impl.clientQueryParam(name, (Object[]) stringValues);
}
} else {
if (values == null || (values.length == 1 && values[0] == null)) {
if (values == null || values.length == 0 || (values.length == 1 && values[0] == null)) {
copy.replaceQueryParam(name, (Object[]) null);
} else {
String[] stringValues = toStringValues(values);
Expand Down

0 comments on commit de389aa

Please sign in to comment.