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 decodes plus sign in query parameter [SPR-17027] #21565

spring-projects-issues opened this issue Jul 10, 2018 · 2 comments
in: test type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Jul 10, 2018

Arne Landwehr opened SPR-17027 and commented

UriComponentsBuilder doesn't encode "+" signs anymore if they are part of a query parameter (#21259), which is the desired behavior according to this.

Unfortunately, HtmlUnitRequestBuilder tries to decode the not encoded plus sign and we therefore end up with a space which breaks the URI.

Here is our concrete setup:

We have a spring boot 2 app with Thymeleaf and automatic UI tests.

Thymeleaf template:

<a th:href="${#mvc.url('controller').arg(date).build()}"


public ModelAndView list(@RequestParam(name = "date", required = false)
                           @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime exportDate)

Once the template is evaluated the final HTML contains the following URI:


(plus sign not encoded)

In our automatic tests the URI is clicked through the WebDriver, and the HtmlUnitRequestBuilder decoded the plus sign. Therefore the controller is called with an invalid ISO fate format:

http://localhost:8080/controller/?date=2017-05-16T00:59:59.999999999 02:00[Europe/Berlin]

(plus sign replaced by whitespace)


Caused by: java.time.format.DateTimeParseException: Text '2017-05-16T00:59:59.999999999 02:00[Europe/Berlin]' could not be parsed, unparsed text found at index 29
	at java.time.format.DateTimeFormatter.parseResolved0(
	at java.time.format.DateTimeFormatter.parse(
	at java.time.ZonedDateTime.parse(
	at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(
	at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(
	... 81 common frames omitted

Affects: 5.0.7

Issue Links:

  • #21577 Support stricter encoding of URI variables in UriComponents ("depends on")
  • #22161 UriComponentsBuilder.toUriString() is broken

1 votes, 5 watchers

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 13, 2018

Rossen Stoyanchev commented

This was caused by the change UriComponents to not encode "+" indeed. The HtmlUnitRequestBuilder is doing the right thing by decoding, as request parameters are expected to be. The real issue is there is no way to control this behavior when using MvcUriComponentsBuilder. However once #21577, we should be able to address this one as well.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 19, 2018

Rossen Stoyanchev commented

I've added an extra encode() method that you can use like this:

<a th:href="${#mvc.url('controller').arg(date).encode().build()}"

This will give you stronger encoding of expanded URI variables.

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

No branches or pull requests

2 participants