diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f9dade9..b6bfca95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC 3.x === +3.1.1 +----- + +### Varnish Cache + +* Fixed `banPath` to escape array of host names to be a correct regular expression. + 3.1.0 ----- diff --git a/src/ProxyClient/Varnish.php b/src/ProxyClient/Varnish.php index a4b7137e..6f7c6b02 100644 --- a/src/ProxyClient/Varnish.php +++ b/src/ProxyClient/Varnish.php @@ -110,7 +110,7 @@ public function banPath(string $path, ?string $contentType = null, array|string| if (!count($hosts)) { throw new InvalidArgumentException('Either supply a list of hosts or null, but not an empty array.'); } - $hosts = '^('.implode('|', $hosts).')$'; + $hosts = '^('.implode('|', array_map(preg_quote(...), $hosts)).')$'; } $headers = [ diff --git a/tests/Unit/ProxyClient/VarnishTest.php b/tests/Unit/ProxyClient/VarnishTest.php index a4784654..7dde033d 100644 --- a/tests/Unit/ProxyClient/VarnishTest.php +++ b/tests/Unit/ProxyClient/VarnishTest.php @@ -71,7 +71,7 @@ public function testBanPath(): void \Mockery::on( function (RequestInterface $request) { $this->assertEquals('BAN', $request->getMethod()); - $this->assertEquals('^(fos.lo|fos2.lo)$', $request->getHeaderLine('X-Host')); + $this->assertEquals('^(fos\.lo|fos2\.lo)$', $request->getHeaderLine('X-Host')); $this->assertEquals('/articles/.*', $request->getHeaderLine('X-Url')); $this->assertEquals('text/html', $request->getHeaderLine('X-Content-Type'));