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

Commit

Permalink
Merge pull request #151 from roelvanduijnhoven/do-not-throw-on-invali…
Browse files Browse the repository at this point in the history
…d-uri

Passing an invalid uri to the referrer header should no longer throw
  • Loading branch information
weierophinney committed Aug 13, 2018
2 parents 6bd2e29 + 9820cbb commit ca6f861
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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());
}
}

0 comments on commit ca6f861

Please sign in to comment.