-
-
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
Unknown field validation #1204
Merged
Merged
Unknown field validation #1204
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It has never been used.
gustavohenke
commented
Jan 17, 2023
@@ -55,9 +55,10 @@ export interface FieldInstance { | |||
originalPath: string; | |||
location: Location; | |||
value: any; | |||
originalValue: any; |
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.
Never really used
Comment on lines
+266
to
+272
// This one seems controversial. | ||
// The nested property wouldn't pass validation - unless it's optional, in which case it's fair to | ||
// argue that 'foo' should be selected? | ||
it('does not select parent when only nested field is known and not an object', () => { | ||
const req = { body: { foo: 'bla' } }; | ||
const instances = selectUnknownFields(req, ['foo.bar'], ['body']); | ||
expect(instances).toHaveLength(0); |
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.
Noteworthy. Let's see what happens after releasing this
gustavohenke
added a commit
that referenced
this pull request
Jan 22, 2023
This was
linked to
issues
Feb 18, 2023
Closed
gustavohenke
added a commit
that referenced
this pull request
Mar 11, 2023
gustavohenke
added a commit
that referenced
this pull request
Mar 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements long awaited exact matching of requests, a.k.a unknown field validations.
It works by
foo.bar
becomes{ foo: { bar: {} }
; thenI made the conscious decision of not including headers and cookies in the default validated locations.
The reason is a bit obvious: browsers will add stuff you weren't expecting.
The API is very flexible too. All of the below are valid:
It's important to notice in the above that checkExact is always the last middleware, or one that wraps others.
That's because it will report fields from chains after it as unknown.
Note: performance wise, this might be slow, depending on what the request and the validation rules look like.
I'm not adding docs in this PR as I wish to revamp them before v7 is released.
To-do list