-
Notifications
You must be signed in to change notification settings - Fork 147
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
Null default with custom validator causes json parse error #122
Comments
Thanks for reporting @RoboPhred. We will look into it ASAP. |
@RoboPhred could you make a PR consisting only of a failing test please? This will be easier for everyone interested in solving this to jump in. Thanks again! |
Sent a pull request with only a test case. I have a possible fix as well: |
@RoboPhred thanks for all the care you put into this. I'll look at it in the next few days. Unfortunately very busy right now. If someone else can review it too it could go faster. |
Your PR has been merged. Thank you very much @RoboPhred and sorry for all the delay. |
When using a command line argument, a custom format function, and a null default, convict attempts to run JSON.parse on the argument.
This is happening in convict 1.0.2, but the code seems to be the same in master.
The issue seems to originate in the getFormat function:
In the return conditional, o.format is a function and o.default is null, resulting in (typeof null) == "object".
This causes the coerce function to try and JSON.parse the content.
This conflicts with the FAQ, stating: "However, you can set a default value to null and if your format doesn't accept null it will throw an error." (#29)
I am currently working around this by setting default to an empty string, as my use case is to check for certain URL formats and I can validate against it.
Example:
The text was updated successfully, but these errors were encountered: