-
Notifications
You must be signed in to change notification settings - Fork 91
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
Custom string validator function adds unwanted key to parent object #271
Comments
Confirmed, for now you can just use |
repro commenting out custom checker function will change the final result const v = new Validator({
// debug: true,
useNewCustomCheckerFunction: true,
defaults: {
object: {
strict: true,
},
string: {
custom(value) {
return value;
},
},
},
});
const schema = {
method: { type: "equal", value: "bar" },
extra: "string",
};
const check = v.compile(schema);
const obj = {};
const res = check(obj);
console.log(obj); |
@erfanium Thanks for looking into this so quickly and for the suggested bypass! |
The issue related to |
@icebob Nah, Run my repro code to better understand it |
Simpler repro: const v = new Validator({
// debug: true,
useNewCustomCheckerFunction: true,
});
const schema = {
extra: { type: "string", custom: value => value }
};
const check = v.compile(schema);
const obj = {};
const res = check(obj);
console.log(obj); So the issue is that FV populates the original object with |
I'm okay with this solution. (In fact, my solution was the same, but in another words) |
Adding a custom string validator function seems to have caused my other validation to stop working correctly.
I have simplified my code down and attached a link to the repo containing an example of the issue I am running into. In the example, I am using a dummy custom string validator function that should not be causing the validation to fail, however when run, the validation fails due to some of my other rules I defined in my schema. If you comment out the custom string validator function, the rest of the rules that previously failed now pass. Thus why I believe the issue seems to stem from defining a custom string validator function.
Link to example repo:
https://github.com/rmattos500/fastest-validator-issue
The text was updated successfully, but these errors were encountered: