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

Commit 9820cbb

Browse files
author
Roel van Duijnhoven
committed
Following #147. Passing an invalid uri to the referrer header should no longer throw.
1 parent 9812b6e commit 9820cbb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Header/AbstractLocation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public function setUri($uri)
7676
$e->getCode(),
7777
$e
7878
);
79+
} catch (UriException\InvalidArgumentException $e) {
80+
throw new Exception\InvalidArgumentException(
81+
sprintf('Invalid URI passed as string (%s)', (string) $uri),
82+
$e->getCode(),
83+
$e
84+
);
7985
}
8086
} elseif (! ($uri instanceof UriInterface)) {
8187
throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');

test/Header/RefererTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,17 @@ public function testCRLFAttack()
7777
$this->expectException(InvalidArgumentException::class);
7878
Referer::fromString("Referer: http://www.example.com/\r\n\r\nevilContent");
7979
}
80+
81+
public function testInvalidUriShouldWrapException()
82+
{
83+
$headerString = "Referer: unknown-scheme://test";
84+
85+
$headers = \Zend\Http\Headers::fromString($headerString);
86+
87+
$result = $headers->get('Referer');
88+
89+
$this->assertInstanceOf(\Zend\Http\Header\GenericHeader::class, $result);
90+
$this->assertNotInstanceOf(\Zend\Http\Header\Referer::class, $result);
91+
$this->assertEquals('unknown-scheme://test', $result->getFieldValue());
92+
}
8093
}

0 commit comments

Comments
 (0)