Skip to content

Commit c5ed718

Browse files
authored
Merge pull request #594 from FriendsOfSymfony/fix/escape-hosts-in-regex
Escape special characters in Varnish::banPath() host patterns
2 parents 8884fa4 + 573854a commit c5ed718

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
66
3.x
77
===
88

9+
3.1.1
10+
-----
11+
12+
### Varnish Cache
13+
14+
* Fixed `banPath` to escape array of host names to be a correct regular expression.
15+
916
3.1.0
1017
-----
1118

src/ProxyClient/Varnish.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function banPath(string $path, ?string $contentType = null, array|string|
110110
if (!count($hosts)) {
111111
throw new InvalidArgumentException('Either supply a list of hosts or null, but not an empty array.');
112112
}
113-
$hosts = '^('.implode('|', $hosts).')$';
113+
$hosts = '^('.implode('|', array_map(preg_quote(...), $hosts)).')$';
114114
}
115115

116116
$headers = [

tests/Unit/ProxyClient/VarnishTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testBanPath(): void
7171
\Mockery::on(
7272
function (RequestInterface $request) {
7373
$this->assertEquals('BAN', $request->getMethod());
74-
$this->assertEquals('^(fos.lo|fos2.lo)$', $request->getHeaderLine('X-Host'));
74+
$this->assertEquals('^(fos\.lo|fos2\.lo)$', $request->getHeaderLine('X-Host'));
7575
$this->assertEquals('/articles/.*', $request->getHeaderLine('X-Url'));
7676
$this->assertEquals('text/html', $request->getHeaderLine('X-Content-Type'));
7777

0 commit comments

Comments
 (0)