Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 966f673

Browse filesBrowse files
committed
escape the regex delimiter character
1 parent ffb07c6 commit 966f673
Copy full SHA for 966f673

File tree

Expand file treeCollapse file tree

2 files changed

+23
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-3
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+1-1Lines 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', preg_replace('/(?<!\\\\)#/', '\\#', $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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+22-2Lines changed: 22 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,24 @@ 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 testSetTrustedHostsEscapesTheRegexDelimiterCharacter()
1882+
{
1883+
Request::setTrustedHosts(array('localhost#,example.com', 'localhost'));
1884+
1885+
$request = Request::create('/');
1886+
$request->headers->set('host', 'localhost');
1887+
$this->assertSame('localhost', $request->getHost());
1888+
}
1889+
1890+
public function testSetTrustedHostsDoesNotEscapeAlreadyEscapedRegexDelimiterCharacters()
1891+
{
1892+
Request::setTrustedHosts(array('localhost\#,example.com', 'localhost'));
1893+
1894+
$request = Request::create('/');
1895+
$request->headers->set('host', 'localhost');
1896+
$this->assertSame('localhost', $request->getHost());
18771897
}
18781898

18791899
public function testFactory()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.