Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sending non array causes UnexpectedTypeException #13804

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

Closed
BruceWouaigne opened this issue Feb 26, 2015 · 7 comments
Closed

Sending non array causes UnexpectedTypeException #13804

BruceWouaigne opened this issue Feb 26, 2015 · 7 comments

Comments

@BruceWouaigne
Copy link
Contributor

Hi guys,

I just notice that, when I send a non array data to a collection form field the ResizeFormListener throws an UnexpectedTypeException before the form validation.

Here is the action

public function indexAction(Request $request)
{
    $form = $this->get('form.factory')->createNamed('', new FooType, null, [
        'method' => 'GET'
    ]);

    $request->query->set('emails', 'a');

    // Throws an exception
    $form->handleRequest($request);

    if ($form->isValid()) {
        die(var_dump('valid'));
    }

    die(var_dump($form->getErrorsAsString()));
}

And the form

class FooType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('emails', 'collection', [
            'type' => 'email'
        ]);
    }

    public function getName()
    {
        return 'foo';
    }
}

Is there anything that I can do to avoid this? By this I mean to get a non valid form instead of an Exception...

I don't really get why https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php#L147 should throws an Exception instead of doing a $data = []; or something.

What do you think?

@BruceWouaigne BruceWouaigne changed the title tran Sending non array causes UnexpectedTypeException Feb 26, 2015
@jakzal
Copy link
Contributor

jakzal commented Mar 4, 2015

I think the behaviour is correct at the moment. You're trying to submit a string instead of a collection. This is unexpected and an exception seems appropriate.

@Tobion
Copy link
Contributor

Tobion commented Mar 4, 2015

The behavior is not correct when an exception is thrown. I already fixed some of those problems in the past where users can throw internal exceptions by submitting unexpected data. This should not be possible. It should either ignore the data or add a form validation error.

@Tobion
Copy link
Contributor

Tobion commented Mar 4, 2015

See #5337 and #8282

@jakzal
Copy link
Contributor

jakzal commented Mar 4, 2015

@Tobion makes sense. I missed your previous PRs.

@BruceWouaigne
Copy link
Contributor Author

Should I do something specific for someone to merge the PR?

@xabbuh
Copy link
Member

xabbuh commented Jun 11, 2015

@BruceWouaigne Which PR do you refer to?

Edit: never mind, got it

webmozart added a commit that referenced this issue Jun 18, 2015
…Submit to ResizeFormListener (BruceWouaigne)

This PR was submitted for the 2.7 branch but it was merged into the 2.8 branch instead (closes #13851).

Discussion
----------

[Form] [EventListener] fixed sending non array data on preSubmit to ResizeFormListener

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13804
| License       | MIT
| Doc PR        |  -

Commits
-------

74d794b [Form] [EventListener] fixed sending non array data on submit to ResizeListener
@webmozart
Copy link
Contributor

Fixed in #13851.

fabpot added a commit that referenced this issue Jun 27, 2015
…tener (BruceWouaigne)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] fixed sending non array data on submit to ResizeListener

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #13804, #13851
| License       | MIT
| Doc PR        |

I agree with @Tobion that #13851 is a bug fix and therefore should be applied on the `2.3` branch too.

Commits
-------

0f185c9 [Form] [EventListener] fixed sending non array data on submit to ResizeListener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants