Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 423a638

Browse files
committed
bug #27152 [HttpFoundation] use brace-style regex delimiters (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [HttpFoundation] use brace-style regex delimiters | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27107 | License | MIT | Doc PR | Commits ------- ae62d9b use brace-style regex delimiters
2 parents 3afdf46 + ae62d9b commit 423a638

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public static function getTrustedProxies()
581581
public static function setTrustedHosts(array $hostPatterns)
582582
{
583583
self::$trustedHostPatterns = array_map(function ($hostPattern) {
584-
return sprintf('#%s#i', $hostPattern);
584+
return sprintf('{%s}i', $hostPattern);
585585
}, $hostPatterns);
586586
// we need to reset trusted hosts on trusted host patterns change
587587
self::$trustedHosts = array();

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
class RequestTest extends TestCase
2020
{
21+
protected function tearDown()
22+
{
23+
Request::setTrustedHosts(array());
24+
}
25+
2126
public function testInitialize()
2227
{
2328
$request = new Request();
@@ -1871,9 +1876,15 @@ public function testTrustedHosts()
18711876

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

1875-
// reset request for following tests
1876-
Request::setTrustedHosts(array());
1881+
public function testSetTrustedHostsDoesNotBreakOnSpecialCharacters()
1882+
{
1883+
Request::setTrustedHosts(array('localhost(\.local){0,1}#,example.com', 'localhost'));
1884+
1885+
$request = Request::create('/');
1886+
$request->headers->set('host', 'localhost');
1887+
$this->assertSame('localhost', $request->getHost());
18771888
}
18781889

18791890
public function testFactory()

0 commit comments

Comments
 (0)