Skip to content

Commit

Permalink
Merge pull request #154 from Zenexer/2.14.x
Browse files Browse the repository at this point in the history
Fix #152: Use strict string comparisons for header keys
  • Loading branch information
Xerkus authored May 20, 2021
2 parents fbf9000 + 0d00f9c commit 180c6c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function get($name)
$key = $this->normalizeFieldName($name);
$results = [];

foreach (array_keys($this->headersKeys, $key) as $index) {
foreach (array_keys($this->headersKeys, $key, true) as $index) {
if ($this->headers[$index] instanceof Header\GenericHeader) {
$results[] = $this->lazyLoadHeader($index);
} else {
Expand Down Expand Up @@ -409,7 +409,7 @@ public function get($name)
public function has($name)
{
$name = $this->normalizeFieldName($name);
return in_array($name, $this->headersKeys);
return in_array($name, $this->headersKeys, true);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,16 @@ public function testCanInjectAlternateHeaderLocatorInstance(): void
$headers->setHeaderLocator($locator);
$this->assertSame($locator, $headers->getHeaderLocator());
}

public function testStrictKeyComparisonInHas(): void
{
$headers = Mail\Headers::fromString("000: foo-bar");
$this->assertFalse($headers->has('0'));
}

public function testStrictKeyComparisonInGet(): void
{
$headers = Mail\Headers::fromString("000: foo-bar");
$this->assertFalse($headers->get('0'));
}
}

0 comments on commit 180c6c7

Please sign in to comment.