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
-------
ae62d9bc81
use brace-style regex delimiters
This commit is contained in:
commit
423a638f3a
@ -581,7 +581,7 @@ class Request
|
||||
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();
|
||||
|
@ -18,6 +18,11 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class RequestTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Request::setTrustedHosts(array());
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$request = new Request();
|
||||
@ -1871,9 +1876,15 @@ class RequestTest extends TestCase
|
||||
|
||||
$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()
|
||||
|
Reference in New Issue
Block a user