Skip to content

Commit

Permalink
use brace-style regex delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed May 6, 2018
1 parent 7a61d31 commit 2d67129
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public static function getTrustedProxies()
public static function setTrustedHosts(array $hostPatterns)
{
self::$trustedHostPatterns = array_map(function ($hostPattern) {
return sprintf('#%s#i', $hostPattern);
return sprintf('{%s}i', $hostPattern);
}, $hostPatterns);
// we need to reset trusted hosts on trusted host patterns change
self::$trustedHosts = array();
Expand Down
15 changes: 13 additions & 2 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

class RequestTest extends TestCase
{
protected function tearDown()
{
Request::setTrustedHosts(array());
}

public function testInitialize()
{
$request = new Request();
Expand Down Expand Up @@ -1871,9 +1876,15 @@ public function testTrustedHosts()

$request->headers->set('host', 'subdomain.trusted.com');
$this->assertEquals('subdomain.trusted.com', $request->getHost());
}

// reset request for following tests
Request::setTrustedHosts(array());
public function testSetTrustedHostsDoesNotBreakOnSpecialCharacters()
{
Request::setTrustedHosts(array('localhost(\.local){0,1}#,example.com', 'localhost'));

$request = Request::create('/');
$request->headers->set('host', 'localhost');
$this->assertSame('localhost', $request->getHost());
}

public function testFactory()
Expand Down

0 comments on commit 2d67129

Please sign in to comment.