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

Passing an invalid uri to the referrer header should no longer throw #151

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Header/AbstractLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public function setUri($uri)
$e->getCode(),
$e
);
} catch (UriException\InvalidArgumentException $e) {
throw new Exception\InvalidArgumentException(
sprintf('Invalid URI passed as string (%s)', (string) $uri),
$e->getCode(),
$e
);
}
} elseif (! ($uri instanceof UriInterface)) {
throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
Expand Down
13 changes: 13 additions & 0 deletions test/Header/RefererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ public function testCRLFAttack()
$this->expectException(InvalidArgumentException::class);
Referer::fromString("Referer: http://www.example.com/\r\n\r\nevilContent");
}

public function testInvalidUriShouldWrapException()
{
$headerString = "Referer: unknown-scheme://test";

$headers = \Zend\Http\Headers::fromString($headerString);

$result = $headers->get('Referer');

$this->assertInstanceOf(\Zend\Http\Header\GenericHeader::class, $result);
$this->assertNotInstanceOf(\Zend\Http\Header\Referer::class, $result);
$this->assertEquals('unknown-scheme://test', $result->getFieldValue());
}
}