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

Closed
spring-issuemaster opened this Issue Jul 10, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster 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()}"

Controller:

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:

http://localhost:8080/controller/?date=2017-05-16T00:59:59.999999999+02:00%5BEurope/Berlin%5D

(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)

Exception:

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(DateTimeFormatter.java:1952)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
	at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(TemporalAccessorParser.java:78)
	at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(TemporalAccessorParser.java:46)
	at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:200)
	... 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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster 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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster 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