-
Couldn't load subscription status.
- Fork 38.8k
Description
Sam Brannen opened SPR-13537 and commented
Status Quo
#18101 brought it to our attention that UriComponentsBuilder returns null for empty request parameters instead of an empty string.
For example, given a request such as http://example.com/login?error, the error request parameter is empty but still present in the query string. Thus we would expect UriComponentsBuilder to store its value as an empty string; however, UriComponentsBuilder currently stores it in its query map as null.
This is contrast to Spring MVC's support for @RequestParameter. When using @RequestParameter in a controller handler method, Spring always passes in an empty string for an empty request parameter value, regardless of whether the = sign is present in the query string.
Analysis
The source of this behavior is in UriComponentsBuilder.query(String), specifically in this line:
queryParam(name, (value != null ? value : (StringUtils.hasLength(eq) ? "" : null)));For empty request parameter values, if the = sign is present, the value is set to an empty string ""; otherwise, the value is set to null.
Furthermore, similar logic exists in UriComponentsBuilder.queryParam(String, Object...): queryParam(...) stores null instead of an empty string for an empty value.
Deliverables
- Ensure that
UriComponentsBuilderstores empty request parameters as empty strings.- Updated both
query(String)andqueryParam(String, Object...) - See TODO in
UriComponentsBuilderTests.
- Updated both
Issue Links:
- HtmlUnitRequestBuilder doesn't handle query parameters without equals sign [SPR-13524] #18101 HtmlUnitRequestBuilder doesn't handle query parameters without equals sign
- Using the MvcUriComponentsBuilder to get a URL to a controller method adds empty parameter when the value is not provided [SPR-14890] #19456 Using the MvcUriComponentsBuilder to get a URL to a controller method adds empty parameter when the value is not provided
Referenced from: commits c52f9d3