-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
fix: correctly select properties of primitives #1279
base: master
Are you sure you want to change the base?
Conversation
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.
Do we have another place to store these tests?
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.
The tested aspects are the field selection + exists
functionality.
I don't feel like they are needed though, everything is covered in some way already.
// wildcard position does not exist | ||
return []; | ||
} | ||
// value is a primitive, there are still still paths to traverse that will be likely undefined, we return the entire path |
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.
Fun fact: you could theoretically go forever now (not for any good reason though), e.g. foo.toFixed.name.toString.length.toFixed
... you just have to keep diving deeper into the prototype!
// value is a primitive, there are still still paths to traverse that will be likely undefined, we return the entire path | |
// value is a primitive, paths being traversed from here might be in their prototype, return the entire path |
@@ -113,14 +115,19 @@ describe('selectFields()', () => { | |||
const req = { | |||
query: { foo: ['bar', 'baz'] }, | |||
}; | |||
const instances = selectFields(req, ['foo[1]'], ['query']); | |||
const instances = selectFields(req, ['foo[1]', 'foo[2]'], ['query']); |
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.
OOC, does this cover anything non-obvious, or is just for thoroughness?
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.
The tested aspects are the field selection + exists
functionality.
I don't feel like they are needed though, everything is covered in some way already.
Description
Fixes #1245
It is correct to assume that primitives will not have properties in a request.
Despite that express-validator should provide the correct result, so if a user wants to validate a non existent property we should treat that as undefined.
Eventually in the future we may also update
FieldInstance
to look something like this:To-do list