Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] weaken the rejection of submitted array data#29911

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
xabbuh wants to merge1 commit intosymfony:3.4fromxabbuh:issue-29809

Conversation

@xabbuh
Copy link
Member

@xabbuhxabbuh commentedJan 16, 2019
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#29809,#29841,#29905
LicenseMIT
Doc PR

It seems that the bugfix made in#29307 seems to break quite some applications. I therefore suggest that we solve the issue a bit different by introducing a newaccept_multiple_values option. This value will benull by default which means no checks will be performed for backwards compatibility. The core form types do explicitly set this value tofalse if they expect the submitted data to be strings. If a form is compound, the option value will automatically default totrue.

Since from my experience most custom form types have child forms, they are already compound and so do accept arrays. Nothing will change for them. Other custom types will not have the check as long as they do not extend one of the built-in types that have this check enabled.

In Symfony 4.3 we can then deprecate thenull default value so that each type must opt for eithertrue orfalse as the value in 5.0.

'error_bubbling' =>false,
'compound' =>$compound,
// submitted arrays are dealt with in data transformers
'accept_multiple_values' =>true,
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Not sure if that's the best name. I could also imagine something likeaccept_array_data.

r8or0pz reacted with thumbs up emoji
Copy link

@YetiCGNYetiCGNJan 17, 2019
edited
Loading

Choose a reason for hiding this comment

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

Suggestion:accept_unstructured_data? "Array" could be mistaken for a flat array without special string keys, just like multiple values on aTextType.

kadet1090 reacted with thumbs up emoji

Choose a reason for hiding this comment

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

'scalar' => false?

@nicolas-grekas
Copy link
Member

Will that make the reported breaks work again? Eg submitting a json-decoded array in a TextType?
I'm not sure we should do this for now: input data should always be strictly validated. Allowing arrays was a really nasty behavior, on the edge of a security risk maybe for some.

@OskarStark
Copy link
Contributor

bugfix made in # seems to break

which PR are you talking about? 🤔

xabbuh reacted with thumbs up emoji

@althaus
Copy link
Contributor

althaus commentedJan 17, 2019
edited
Loading

@OskarStark See#29809 for the main discussion triggered by PR#29307 .

OskarStark and xabbuh reacted with thumbs up emoji

@althaus
Copy link
Contributor

The core form types do explicitly set this value to false if they expect the submitted data to be strings.

What'd the behaviour of thenull form type which defaults to TextType? My reading is that those "evil" forms are still broken?

@xabbuh
Copy link
MemberAuthor

@nicolas-grekas As long as you do not explicitly set theaccept_multiple_values totrue yourself array values would still be rejected (that's why we need to be explicit about this in the core form types).

But what this will allow easily again having a custom type like this:

class UnstructuredTypeextends AbstractType{}

@althaus Yes, if you are not explicitly about the type being used and theTextType is the result of the guessing process, this PR does not change anything for you.

@alexander-schranz
Copy link
Contributor

alexander-schranz commentedJan 17, 2019
edited
Loading

@xabbuh if I'm interpereting it correctly I could use for unstructured data this then:

useSymfony\Component\Form\Extension\Core\Type\FormType;$builder->add('some_unstructured_data', FormType::class');

@xabbuh
Copy link
MemberAuthor

@alexander-schranz Yes, that should work (that basically is the same as this test:https://github.com/symfony/symfony/pull/29911/files#diff-de65be85a5affed1f499b79d96965419R1062). But I'd be happy if you could confirm that in your application context.

$this->form->add($this->getBuilder('foo',null,null, ['compound' =>true])->getForm());

$this->form->submit([
'foo' => ['foo'],
Copy link
Contributor

@alexander-schranzalexander-schranzJan 17, 2019
edited
Loading

Choose a reason for hiding this comment

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

would also add test for a nested array not just a list:

['foo' => ['foo' =>'foo','bar' => ['baz' =>'baz',    ]  ]]

@xabbuh

YetiCGN reacted with thumbs up emoji
@alexander-schranz
Copy link
Contributor

@xabbuh will test it in the application at the evening. Thank you for having a look at the issue!

xabbuh and althaus reacted with thumbs up emoji

@xabbuh
Copy link
MemberAuthor

@alexander-schranz makes sense, done

{
$resolver->setDefaults([
'compound' =>false,
'accept_multiple_values' =>false,
Copy link
Contributor

Choose a reason for hiding this comment

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

@xabbuh this should set to true until 5.0 to avoid the bc break which was introduce in 3.4.21, else applications which did work before 3.4.21 still would crash.

@nicolas-grekas
Copy link
Member

I'm not sure at all we should do this change.
The behavior change we introduced is a bug fix.
I'm sorry some "hacked" the component and are caught by the fix, but every bug fix does that potentially.
Does this PR provide something that cannot be achieved otherwise?
Adding a new option means added complexity for everyone, better think twice about it.

dmaicher reacted with thumbs up emoji

@althaus
Copy link
Contributor

I'm sorry some "hacked" the component

I'm pretty sure that 9 out of 10 didn't do this on purpose, but either by accident or due to lacking docs back then. The Form component really can be a b**ch sometimes. It's the only one forcing us to rework code parts every now and then due to some "fix". :/

I can also see that adding a fire-and-forget option just for this small thing on all those classes could raise more headache than it solves. So I'd be glad if someone can imagine a solution working for both sides.

dbaida reacted with thumbs up emoji

@fnagel
Copy link
Contributor

I'm sorry some "hacked" the component and are caught by the fix, but every bug fix does that potentially.

True that, but even big bundles like RestBundle using that "hack" and recommend it in their docs.

@nicolas-grekas
Copy link
Member

True that, but even big bundles like RestBundle using that "hack" and recommend it in their docs.

time to fix them!

fnagel, dmaicher, xabbuh, yceruto, and VSilantyev reacted with thumbs up emoji

@dmaicher
Copy link
Contributor

I'm also not sure I would fix this by adding another option. I find it too confusing to have

  • compound
  • multiple
  • accept_multiple_values (or whatever new name we pick)

In the end the fix for all affected users would be something like this here, or not?
sulu/sulu#4349

@xabbuh
Copy link
MemberAuthor

@dmaicher Basically yes, except that the type could be shortened to not have to include theconfigureOptions() method at all.

@xabbuhxabbuh closed thisJan 25, 2019
@xabbuhxabbuh deleted the issue-29809 branchJanuary 25, 2019 10:10
@xabbuh
Copy link
MemberAuthor

closing here as it doesn't look like the proposed change is of interest

alexander-schranz, sophie-la-li, and YetiCGN reacted with confused emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

3 more reviewers

@YetiCGNYetiCGNYetiCGN left review comments

@alexander-schranzalexander-schranzalexander-schranz left review comments

@asentnerasentnerasentner left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

10 participants

@xabbuh@nicolas-grekas@OskarStark@althaus@alexander-schranz@fnagel@dmaicher@YetiCGN@asentner@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp