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

Allow timestamp with both fractions and offset #1061

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

liskaant
Copy link
Contributor

Regex parsing for JSON timestamps does not allow both fractional seconds and also express timezone in an offset format. For example the following timestamp does not match: 2025-01-27T11:42:15.689800+00:00.

This change simply moves the match group for fractions before the offset capture and makes it optional. The ordering and indexes of matches are kept the same.

It also allows fractions shorter than 3 digits, since RFC 3339 does not place such restriction and the fraction parsing later in this function handles it just fine.

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2025

CLA assistant check
All committers have signed the CLA.

@nicksnyder nicksnyder changed the title fix(decode-json): allow timestamp with both fractions and offset Allow timestamp with both fractions and offset Jan 27, 2025
@nicksnyder
Copy link
Member

Thanks for the contribution @liskaant! Would you be able to add a test case?

@liskaant liskaant force-pushed the fix-json-decode-timestamp branch from b39cc92 to b7c62cc Compare January 28, 2025 16:05
@liskaant
Copy link
Contributor Author

@nicksnyder Added a few. Hopefully in the right place, since I couldn't find any existing timestamp decoding tests. If not, please point me to the right place.

@nicksnyder nicksnyder requested a review from timostamm January 28, 2025 21:21
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Protobuf conformance test suite includes several dozen tests for parsing Timestamp from JSON. That's why you didn't find explicit tests.

The suite does not cover fractions with less than 3 digits and fractions with a TZ offset, but both should be valid. Thanks for the fix and the tests, @liskaant.

@timostamm timostamm merged commit 5749c55 into bufbuild:main Jan 29, 2025
21 checks passed
@liskaant liskaant deleted the fix-json-decode-timestamp branch January 29, 2025 11:49
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.

4 participants