-
Notifications
You must be signed in to change notification settings - Fork 354
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
feat: encoding > allowReserved support #630
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.
I've dropped some comments, but the direction is overall ok!
Can you add a changelog line?
for (const encoding of encodings) { | ||
const allowReserved = get(encoding, 'allowReserved', false); | ||
const property = encoding.property; | ||
const value = shallowParsedTarget[property]; |
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.
What does shallow
specifically mean here?
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 had trouble naming that.
Basically it should mean that URL is split by &
and the key-val pairs are extracted. But percent-encoded entities hadn't been decoded yet.
We need it in that form because:
- we need key-val pairs in order to match key names with relevant encoding definitions
- we need before-percent-decoding values in order to look for forbidden characters
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.
Path and queryParams?
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.
Quite unsure what do you mean by path and queryParams. We are dealing here with body payload.
test-harness/specs/validate-body-params/form-data-allow-reserved-fail.oas3.txt
Show resolved
Hide resolved
@@ -27,7 +27,7 @@ paths: | |||
====server==== | |||
mock -p 4010 | |||
====command==== | |||
curl -i -X POST http://localhost:4010/path -H "Content-Type: application/x-www-form-urlencoded" --data "status=ooopsie!" | |||
curl -i -X POST http://localhost:4010/path -H "Content-Type: application/x-www-form-urlencoded" --data "status=ooopsie%21" |
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.
Just to make sure I understand this correctly — since !
is a reserved character and allowReserved
is false by default, you have effectively encoded it so that it passes the validation and goes through the following validation step, right?
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.
Exactly. And this is the place where I doubt in OpenApi 3 spec. I mean having allowReserved=false
by default sounds reasonable. However, I think it will end with lots of people complaining that prism has a bug.
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.
It depends, usually the clients handle the encoding automatically and even curl has an option
--data-urlencode
.
//cc @philsturgeon for awareness but I do not see this as a problem
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.
Updated to use --data-urlencode
👍
Changelog line added 👍 |
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.
Looks good; unfortunately we had to move some of the logic in the http package but I guess there's no really other way.
@philsturgeon do you want to have a quick look here just to make sure it's ok from a feature standpoint?
If we could NOT support this we'd keep the things a little bit better in the place they should be and be like man respect the standard
BTW — personal opinion, this OAS flag is just…non sense and I would love ❤️ to know the rationale behind this.
test-harness/specs/validate-body-params/form-data-allow-reserved-fail.oas3.txt
Show resolved
Hide resolved
@@ -27,7 +27,7 @@ paths: | |||
====server==== | |||
mock -p 4010 | |||
====command==== | |||
curl -i -X POST http://localhost:4010/path -H "Content-Type: application/x-www-form-urlencoded" --data "status=ooopsie!" | |||
curl -i -X POST http://localhost:4010/path -H "Content-Type: application/x-www-form-urlencoded" --data "status=ooopsie%21" |
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.
It depends, usually the clients handle the encoding automatically and even curl has an option
--data-urlencode
.
//cc @philsturgeon for awareness but I do not see this as a problem
Looks great feature wise! |
Closes #497
WIP: needs code style refinement
Checklist
What kind of change does this PR introduce?
encoding.style
is only applied forapplication/application/x-www-form-urlencoded
encoding.style
is applied to all uri parts (before it was only applied to first one)qs
package to decode UrlEncoded payload. It was used internally by fastify'sform-body
pluginDoes this PR introduce a breaking change?
No