Skip to content

Commit

Permalink
Fix: URIBuilder.getFirstQueryParam throws NPE when query is emty (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
skssxf authored and ok2c committed Dec 19, 2023
1 parent d1c77bc commit d39031d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ public List<NameValuePair> getQueryParams() {
* @since 5.2
*/
public NameValuePair getFirstQueryParam(final String name) {
if (queryParams == null) {
return null;
}
return queryParams.stream().filter(e -> name.equals(e.getName())).findFirst().orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ public void testGetFirstNamedParameter() throws Exception {
//
uribuilder = new URIBuilder("http://localhost:80/?param=some%20other%20stuff&blah=blah&blah=blah2");
Assertions.assertEquals("blah", uribuilder.getFirstQueryParam("blah").getValue());
uribuilder.removeQuery();
Assertions.assertNull(uribuilder.getFirstQueryParam("param"));
}

@Test
Expand Down

0 comments on commit d39031d

Please sign in to comment.