Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Content-Type paramater does not trim paramater name #220

@cody121

Description

@cody121

Hello,

I am getting filenames for attachments using the getParameter() on the content-type header. I noticed some email parts that were supposed to be attachments did not have a filename. Inspecting the source header, I could see that there was in fact a filename set. Further inspection showed that the parameter name was being added with a leading space. I would expect that leading spaces would be trimmed.

Thanks,

Cody

Code to reproduce the issue

use Zend\Mail\Header\ContentType;
$ct = ContentType::fromString('Content-Type: text/plain; charset=utf-8; name="logfile.log";');
printf('r1 "%s"'.PHP_EOL, $ct->getParameter('name'));
printf('r2 "%s"'.PHP_EOL, $ct->getParameter(' name'));
var_dump($ct);

Actual results

r1 ""
r2 "logfile.log"
object(Zend\Mail\Header\ContentType)#3 (3) {
  ["type":protected]=>
  string(10) "text/plain"
  ["encoding":protected]=>
  string(5) "ASCII"
  ["parameters":protected]=>
  array(2) {
    ["charset"]=>
    string(5) "utf-8"
    [" name"]=>
    string(11) "logfile.log"
  }
}

My Fix

I would not presume to understand the best place to resolve this, but this hack solved my problem for the time being

$ diff ContentType.php ContentType.php.new
55c55
<                 $header->addParameter($values[$i], $value);
---
>                 $header->addParameter(trim($values[$i]), $value);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions