Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HtmlUnitRequestBuilder doesn't handle query parameters without equals sign [SPR-13524] #18101

Closed
spring-projects-issues opened this issue Sep 30, 2015 · 3 comments
Assignees
Labels
in: test type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 30, 2015

Christopher Smith opened SPR-13524 and commented

Blank request parameters are used occasionally to conditionally turn on messages inside templates. For example, Spring Security uses /login?error to indicate that a username/password pair was incorrect. However, HtmlUnitRequestBuilder currently attempts to decode null values for query parameters which results in a NullPointerException. See the following stack trace for details.

Caused by: java.lang.NullPointerException
	at java.net.URLDecoder.decode(URLDecoder.java:136)
	at org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilder.params(HtmlUnitRequestBuilder.java:365)
	at org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilder.buildRequest(HtmlUnitRequestBuilder.java:121)
	at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:140)
	at org.springframework.test.web.servlet.htmlunit.MockMvcWebConnection.getResponse(MockMvcWebConnection.java:122)

Adding an equals sign with no content prevents the exception but shouldn't be required, especially since other Spring components generate redirects with this form.


Affects: 4.2 GA

Issue Links:

  • #18113 UriComponentsBuilder interprets empty request parameters as null

Referenced from: commits 283fc94, 61a46db

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 30, 2015

Sam Brannen commented

Fixed in GitHub commit 283fc94:

Support null query param values in HtmlUnitRequestBuilder

Prior to this commit, HtmlUnitRequestBuilder would incorrectly attempt
to decode null values for query parameters (i.e., query parameters such
as 'error' in 'http://example.com/login?error') which resulted in a
NullPointerException since URLDecoder.decode() does not support null
values.

This commit fixes this issue by ensuring that HtmlUnitRequestBuilder
only attempts to decode non-null query parameter values.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 4, 2015

Sam Brannen commented

See also: #18113

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 4, 2015

Sam Brannen commented

Refined in GitHub commit 61a46db:

Treat query param w/o "=" as empty string in HtmlUnitRequestBuilder

Prior to this commit, HtmlUnitRequestBuilder stored empty query parameters declared without an equals sign as null (i.e., query parameters such as error in http://example.com/login?error).

This commit addresses this issue by ensuring that HtmlUnitRequestBuilder treats all empty query parameter values as empty strings. Consequently, query strings such as ?error and ?error= now both result in error being stored as an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test type: bug
Projects
None yet
Development

No branches or pull requests

2 participants