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

Strings matching ISO datetime fail to match explicit pattern #289

Open
hannes-ucsc opened this issue Mar 24, 2022 · 1 comment
Open

Strings matching ISO datetime fail to match explicit pattern #289

hannes-ucsc opened this issue Mar 24, 2022 · 1 comment

Comments

@hannes-ucsc
Copy link

I expect both to validate but only the latter one does.

https://www.jsonschemavalidator.net/s/aGIeEynR

https://www.jsonschemavalidator.net/s/v9Or7B17

The second case just shortens the year to three digits, I suspect that something in the engine automatically detects the ISO datetime in the value and prevents the match. Note that the pattern in the schema is stricter than `"format": "date-time" which is why I can't use the latter in my particular use case.

@hannes-ucsc hannes-ucsc changed the title Strings matching ISO time fail to match explicit pattern Strings matching ISO datetime fail to match explicit pattern Mar 24, 2022
@elgonzo
Copy link

elgonzo commented Apr 3, 2022

Nice find!

I agree with the suspicion that Json.Newtonsoft.Schema (or Newtonsoft.Json) is somewhere somehow unwarrantedly trying to roundtrip the string as a DateTime (or similar) and back to a string.

I think this is why your first example fails: Note the trailing insignificant 0 at the fractions of seconds "2020-05-01T04:26:07.021870Z". This string, when roundtripped through DateTime, could result in the string "2020-05-01T04:26:07.02187Z", thus the regex pattern will not match.

Empirical evidence supporting my theory/suspicion:


It should be possible to work-around this bug in your own code by using an appropriately configured JsonReader (JsonReader.DateParseHandling) to read the json data.

For the online validator this would mean an update to the code backing this service, and until this happens the online validator is unfortunately essentially unreliable.

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

No branches or pull requests

2 participants