-
Notifications
You must be signed in to change notification settings - Fork 325
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
date-time validation is too lenient #508
Comments
Also, the offset is not following the RFC-3339 specification. |
The current date time validator is based on regex and it is very hard to cover all the edge cases. I would be very happy to accept a PR if you guys come up with a new regex to fill in the gaps. Thanks. |
Co-authored-by: Matti Hansson <[email protected]>
@aznan2 I want to test the new regex with more test cases so I have synched the date-time.json from the official test suite. It is broken with one of the test cases.
The test case is disabled currently and I am wondering if you could take a look to get this test case resolved. The test case is located at https://github.com/networknt/json-schema-validator/blob/master/src/test/java/com/networknt/schema/V4JsonSchemaTest.java#L45 |
Sure, I'll check it out. |
Please feel free to ignore this, but if you want another solution: https://github.com/ethlo/itu - A dependency-free RFC-3339 parser. Full disclosure: I'm the author |
@ethlo Thanks a lot for the idea. I have checked the lib and it is a very good candidate. It is green without any dependency, very small and built with Java 8. Let's try the regex first and move to it if we cannot resolve it with regex. |
The issue is that SimpleDateFormat doesn't handle leap seconds. The new PR uses ethlo's ITU to accept leap seconds, though it's still not 100%. ITU's implementation only checks that the leap second occurs on July or December 31, so it accepts |
* Make date-time validation align with RFC3339 (#508) * Make date-time validation handle leap seconds (#508) Co-authored-by: Matti Hansson <[email protected]> Co-authored-by: mathan <[email protected]>
~~Also, I released a new version, with some cleanup and better UPDATE: I have just released 1.5.1 with proper support for leap seconds! https://github.com/ethlo/itu/releases/tag/v1.5.1 IMPORTANT: Please take note that the parser no longer accepts null/empty since version 1.5.0, to be in line with Also, I think that the performance of ITU is very much in line with the performance of this library: https://github.com/ethlo/itu#performance Thank you. |
Co-authored-by: Matti Hansson <[email protected]>
We upgraded to 1.0.68 and the above strict validation for offset is breaking all our server API's!
Is there a way to configure the DateTimeValidator to be backwards compatible? |
@dhpalan This is not "strict" validation, it is validation according to the RFC3339 specification. Any client that uses There are ways that you can inject your own validator(s), but there are people that know more about that than I do, and this ticket is not the right place to address such a request. |
Since upgrading to the latest version will break our production, We have decided to upgrade our java project in two phases. If the |
@dhpalan I think that is a very good plan to encourage users to use the RFC3339 format as it is the standard. |
Validation of
date-time
format accepts the value2022-02-03T11:47:43.123
as valid, even though a time zone offset or Z is required.From the JSON schema spec, section 7.3.1:
And looking at RFC 3339, section 5.6:
The
time-offset
part is not optional.To make it backwards compatible, perhaps the lenient validation could be available as an option, though in that case I think the stricter version should be the default behavior.
The text was updated successfully, but these errors were encountered: