Skip to content
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(controller): Fix false booleans in multipart/form-data #49515

Merged

Conversation

nickvergessen
Copy link
Member

Summary

I was debugging an issue reported by our frontenders with a new API (ref nextcloud/spreed#13871 (comment))
Turns out sending the boolean false in a post request sees it as "false" and therefore evaluates to true.
We have some code in place to "sometimes" translate that to false (see diff). I now need to extend this to multipart/form-data.

But at the same time I wonder why the check is there at all? When the controller requests a boolean, shouldn't we always convert "false" to false independent from request type?

Checklist

Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about query parameters? There we currently only allow 0/1 for booleans and openapi-extractor has a quirk to workaround this, but it would be great if we could send proper boolean true/false

@nickvergessen
Copy link
Member Author

What about query parameters? There we currently only allow 0/1 for booleans and openapi-extractor has a quirk to workaround this, but it would be great if we could send proper boolean true/false

That is already working properly with the settype path:
https://3v4l.org/SolRs

<?php

$value = '0';
settype($value, 'bool');
var_dump($value);
// bool(false)

$value = 'false';
settype($value, 'bool');
var_dump($value);
// bool(true)

In alignment via chat, I will make it match in all cases when the value is 'false' and the controller wants a boolean

@nickvergessen nickvergessen force-pushed the bugfix/noid/boolean-false-in-multipart-form-data branch from e2318f2 to 1909b98 Compare November 28, 2024 11:19
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is already working properly with the settype path:

Hm ok then I have to check again 🤔

@nickvergessen nickvergessen merged commit dd101dd into master Nov 28, 2024
185 checks passed
@nickvergessen nickvergessen deleted the bugfix/noid/boolean-false-in-multipart-form-data branch November 28, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants