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

[Mime] handle passing custom mime types as string #36716

Merged
merged 1 commit into from May 9, 2020

Conversation

mcneely
Copy link
Contributor

@mcneely mcneely commented May 5, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #36715
License MIT
Doc PR none
Fix's issue where custom mimetypes were failing

@xabbuh
Copy link
Member

xabbuh commented May 6, 2020

I am not sure that this qualifies as a bug fix. Reading the code it clear that the constructor expects a list of extensions not a single one. Maybe we should clarify that by adding a docblock?

Like this:

/**
 * @param array<string, array<int, string>> $map
 */
public function __construct(array $map = [])
{
    // ...
}

@mcneely
Copy link
Contributor Author

mcneely commented May 6, 2020

@xabbuh
The bugfix is on line 56, right now it's setting the mimetype for an extension as a string and not an array. getMimeTypes is expected to return an array but when it gets the extension it's a string and throws an error.

@xabbuh
Copy link
Member

xabbuh commented May 6, 2020

What I wanted to say is that this was probably not supposed to work:

$mt = new MimeTypes([
    'text/bar' => 'foo',
]);

It should have been written like this instead:

$mt = new MimeTypes([
    'text/bar' => ['foo'],
]);

@mcneely
Copy link
Contributor Author

mcneely commented May 6, 2020

What's wrong with adding that in?

@nicolas-grekas nicolas-grekas changed the title Fix for #36715 [Mime] handle passing custom mime types as string May 6, 2020
@xabbuh
Copy link
Member

xabbuh commented May 7, 2020

There's nothing wrong with it. I am just questioning whether this has been an intended usage. Depending on the answer this patch would either be a bugfix or a new feature.

@mcneely
Copy link
Contributor Author

mcneely commented May 7, 2020

@xabbuh I have removed the line of convenience code you're so caught up on. Now it's only a bug fix.

@mcneely
Copy link
Contributor Author

mcneely commented May 7, 2020

@nicolas-grekas I think the 7.1 integration just needs to be rerun, some sort of hiccup, probably because of 2 commits back to back.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 7, 2020

At least there is a bug that if you pass a string, it explodes.
I'm fine merging as a bugfix for this reason on my side.

@xabbuh
Copy link
Member

xabbuh commented May 8, 2020

@xabbuh I have removed the line of convenience code you're so caught up on. Now it's only a bug fix.

I think there is a misunderstanding here. My concern was not if changing that line is important, but whether or not we want to treat the whole patch as a bugfix or as a new feature. I can see good reasons for both that's why I wanted to discuss that.

I misunderstood the comment I replied to. I understand the issue now and the proposed change fixes it. 👍

@@ -51,7 +51,8 @@ public function __construct(array $map = [])
$this->extensions[$mimeType] = $extensions;

foreach ($extensions as $extension) {
$this->mimeTypes[$extension] = $mimeType;
$this->mimeTypes[$extension] = $this->mimeTypes[$extension] ?? [];
array_push($this->mimeTypes[$extension], $mimeType);
Copy link
Member

Choose a reason for hiding this comment

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

You can shorten the patch a bit by using []:

$this->mimeTypes[$extension][] = $mimeType;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

with a minor change

src/Symfony/Component/Mime/MimeTypes.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented May 9, 2020

Thank you @mcneely.

@fabpot fabpot merged commit 6310084 into symfony:4.4 May 9, 2020
@fabpot fabpot mentioned this pull request May 16, 2020
This was referenced May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants