-
Notifications
You must be signed in to change notification settings - Fork 4
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
[DUOS-2720] Fix date and uri validation #2354
Conversation
regenerate validation; re-implement uri validation;
const formats0 = { "_items": ["require(\"ajv-formats/dist/formats\").", { "str": "fullFormats" }, ""] }.date; | ||
const dateRegex = /^\d{4}-(02-(0[1-9]|[12][0-9])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))$/; | ||
const dateValid = (value) => dateRegex.test(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the meat of the fix - this date regex comes from /src/components/forms/formValidation.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this validation file is automatically generated from ajv
, if this change is implemented manually will it be overwritten the next time we run ajv
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is a script that we have to run that re-writes this file. Most of the changes here are from that process. This is not a sustainable process and we need to move away from it which is what I'm looking into now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question:
const formats0 = { "_items": ["require(\"ajv-formats/dist/formats\").", { "str": "fullFormats" }, ""] }.date; | ||
const dateRegex = /^\d{4}-(02-(0[1-9]|[12][0-9])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))$/; | ||
const dateValid = (value) => dateRegex.test(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this validation file is automatically generated from ajv
, if this change is implemented manually will it be overwritten the next time we run ajv
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 👍
Addresses
https://broadworkbench.atlassian.net/browse/DUOS-2720
Summary
There are some issues with trying to pass custom validator functions into the Ajv-generated validator code. In our case, we have custom functions in
JsonSchemaUtils.js
but it doesn't look like we're actually passing them into the script that does code generation (in a separate script). Therefore, they're never actually used.As a workaround, this PR fixes the date validation and re-implements the URI validation that was previously commented out due to this same problem. These were being pulled from
ajv-formats
but seem to be intermittently undefined, i.e., the validation function would exist for one field, but not for another later on in the validation process.Have you read Terra's Contributing Guide lately? If not, do that first.