Fix parsing of date/time query parameter values with an offset ahead of UTC #2703
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to the documentation on request matching, Wiremock should be able to handle offsets in date/time query parameter values in all of the following three cases:
In other words, it should be able to parse a date/time query parameter value with an offset ahead of UTC (
+HH:mm
), an offset of zero (Z
) and an offset behind UTC (-HH:mm
).Right now only the last two work. Offsets ahead of UTC found in query parameters cannot be matched due to the
+
also having semantics in URL encoding. That is, in URL encoded strings+
represents a space and as a result2021-06-24T13:40:27+01:00
is decoded to2021-06-24T13:40:27 01:00
which results in aDateTimeParseException
.To avoid that, this PR adds a check to see whether the parameter's value is an ISO-8601 formatted date/time value and, if so, returns it without decoding it first. That way
2021-06-24T13:40:27+01:00
remains as is whilehello+world
is still decoded tohello world
. In other words, the fix only applies to strings that can successfully be parsed byISO_OFFSET_DATE_TIME
, everything else is treated the same as before.A helpful discussion of the problem above is available in the note found here. The context of the note is Apple technologies, not Java, but this problem is independent of the technologies used.
A unit test which breaks with the current implementation has also been added.
References
Wiremock documentation where the expected behaviour is described: https://wiremock.org/docs/request-matching/#local-vs-zoned
Submitter checklist
#help-contributing
or a project-specific channel like#wiremock-java