eclipse-ee4j / eclipse-ee4j/jersey
Empty QueryParam leads to collection of one null element
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
It seems like #563 has resurfaced. By passing `?param=` that is, a param without a value, to a collection parameter, for example `Set`, leads to this parameter containing one null element.
Test case provided by @joschi in the dropwizard project (https://github.com/dropwizard/dropwizard/issues/3435) as follows:
```java
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
public class Issue3435 extends JerseyTest {
@Override
protected Application configure() {
return new ResourceConfig(TestResource.class);
}
@Test
public void emptyStringQueryParamReturnsListWithOneNullElement() {
Response response = target("test")
.queryParam("list", "")
.request()
.get();
assertEquals(200, response.getStatus());
assertEquals("1: [null]", response.readEntity(String.class));
}
@Test
public void missingQueryParamReturnsEmptyList() {
Response response = target("test")
.request()
.get();
assertEquals(200, response.getStatus());
assertEquals("0: []", response.readEntity(String.class));
}
@Test
public void filledQueryParamReturnsListWithOneElement() {
Response response = target("test")
.queryParam("list", "ec0cf621-d744-4a1c-b1d8-4b8a44b3dad7")
.request()
.get();
assertEquals(200, response.getStatus());
assertEquals("1: [ec0cf621-d744-4a1c-b1d8-4b8a44b3dad7]", response.readEntity(String.class));
}
@Path("test")
public static class TestResource {
@GET
public String test(@QueryParam("list") List list) {
return list.size() + ": " + list.toString();
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.