From 0d00f9cb3bcc3906dc0efe2940fea84d6d6d3312 Mon Sep 17 00:00:00 2001 From: Paul Buonopane Date: Wed, 19 May 2021 11:51:48 -0400 Subject: [PATCH] Fix #152: Use strict string comparisons for header keys Signed-off-by: Paul Buonopane --- src/Headers.php | 4 ++-- test/HeadersTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Headers.php b/src/Headers.php index dc4e0afd..012297a7 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -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 { @@ -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); } /** diff --git a/test/HeadersTest.php b/test/HeadersTest.php index 41bcd68c..a8174645 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -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')); + } }