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

[Mime] Throw InvalidArgumentException on invalid form field type inside array#52033

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

Merged
nicolas-grekas merged 1 commit intosymfony:6.4froml-naumann:dx/form-data-part
Oct 17, 2023

Conversation

l-naumann
Copy link
Contributor

@l-naumannl-naumann commentedOct 13, 2023
edited by OskarStark
Loading

QA
Branch?6.4
Bug fix?no
New feature?no
Deprecations?no
Ticketsn/a
LicenseMIT

Example code:

$f =newFormDataPart(['foo' => ['bar' =>'baz','qux' => ['quux' =>1,                ],            ],        ]);$f->getParts();

Currently, when you use a disallowed type inside an array, a TypeError is thrown:
Symfony\Component\Mime\Part\Multipart\FormDataPart::configurePart(): Argument #2 ($part) must be of type Symfony\Component\Mime\Part\TextPart, int given

This change adds a clearly understandable error message:
The value of the form field "foo[qux][quux]" can only be a string, an array, or an instance of TextPart ("int" given).

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@@ -75,6 +75,10 @@ private function prepareFields(array $fields): array
return;
}

if (!\is_string($item) && !$item instanceof TextPart) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can move this check to the constructor directly? That would be more consistent as we already check some of that there.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I also considered this, but in my opinion it has two disadvantages:

  1. We have to traverse through the array recursively. InprepareFields this is already the case, but in the constructor we only traverse at top-level.
  2. We don't have the field name in form of "foo[qux][quux]" in the constructor. Either we cannot include it in the error message, or we have to generate it redundantly.

Also we already have a check (regarding the form field values with integer keys) insideprepareFields, so I don't feel like adding another check there affects the consistency much.

How about we remove the check in the constructor altogether? All the checks could be done insideprepareFields and the constructor would look like this:

 public function __construct(array $fields = [])    {        parent::__construct();        $this->fields = $fields;        // HTTP does not support \r\n in header values        $this->getHeaders()->setMaxLineLength(\PHP_INT_MAX);    }

Copy link
Member

Choose a reason for hiding this comment

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

Having all the checks in prepareFields works for me.

@nicolas-grekas
Copy link
Member

Thank you@l-naumann.

@nicolas-grekasnicolas-grekas merged commitc6930e3 intosymfony:6.4Oct 17, 2023
@l-naumannl-naumann deleted the dx/form-data-part branchOctober 17, 2023 12:08
@xabbuhxabbuh mentioned this pull requestAug 13, 2024
xabbuh added a commit that referenced this pull requestAug 13, 2024
This PR was merged into the 6.4 branch.Discussion----------[Mime]  fix test| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| Issues        || License       | MITupdates the test added in#57892 to reflect the change of behavior introduced with#52033Commits-------2e8b9ce fix test
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

4 participants
@l-naumann@carsonbot@nicolas-grekas@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp