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

Fix parsing of date/time query parameter values with an offset ahead of UTC #2703

Merged
merged 1 commit into from
May 15, 2024

Conversation

papiomytoglou
Copy link
Contributor

@papiomytoglou papiomytoglou commented May 2, 2024

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:

/resource?date=2021-06-24T13:40:27+01:00
/resource?date=2021-06-24T13:40:27Z
/resource?date=2021-06-24T13:40:27-01:00

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 result 2021-06-24T13:40:27+01:00 is decoded to 2021-06-24T13:40:27 01:00 which results in a DateTimeParseException.

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 while hello+world is still decoded to hello world. In other words, the fix only applies to strings that can successfully be parsed by ISO_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

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to [wiremock.org](https://github.com/wiremock/wiremock.org)

@papiomytoglou papiomytoglou requested a review from a team as a code owner May 2, 2024 19:52
@papiomytoglou papiomytoglou force-pushed the fix_offsets_ahead_of_UTC branch from 373884a to d660fa9 Compare May 2, 2024 19:57
@papiomytoglou papiomytoglou changed the title fix: fix parsing of ISO-8601 formatted date/time values with an offset ahead of UTC fix: fix parsing of date/time values with an offset ahead of UTC May 2, 2024
@papiomytoglou papiomytoglou changed the title fix: fix parsing of date/time values with an offset ahead of UTC Fix parsing of date/time values with an offset ahead of UTC May 2, 2024
@papiomytoglou papiomytoglou force-pushed the fix_offsets_ahead_of_UTC branch from d660fa9 to d69c5a3 Compare May 2, 2024 20:10
@papiomytoglou papiomytoglou changed the title Fix parsing of date/time values with an offset ahead of UTC Fix parsing of date/time query parameter values with an offset ahead of UTC May 2, 2024
@papiomytoglou papiomytoglou force-pushed the fix_offsets_ahead_of_UTC branch 4 times, most recently from 69aa904 to f6f1cc1 Compare May 4, 2024 12:11
@papiomytoglou papiomytoglou force-pushed the fix_offsets_ahead_of_UTC branch from f6f1cc1 to e29ec8d Compare May 4, 2024 20:49
@dieppa dieppa self-assigned this May 14, 2024
@dieppa
Copy link
Contributor

dieppa commented May 14, 2024

Thanks, @papiomytoglou , we are reviewing it 👀

@dieppa
Copy link
Contributor

dieppa commented May 15, 2024

Thanks @papiomytoglou ,

Reviewed and merged!

@dieppa dieppa merged commit 83ae2df into wiremock:master May 15, 2024
9 checks passed
@papiomytoglou papiomytoglou deleted the fix_offsets_ahead_of_UTC branch July 5, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants