Skip to content

Commit 88e4d42

Browse files
committed
Merge branch 'remove-xkey-tag-escaping'
2 parents 9fe2f58 + 8b80955 commit 88e4d42

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ Changelog
33

44
See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpCache/releases).
55

6+
2.3.1
7+
-----
8+
9+
### Varnish
10+
11+
* Fixed: Do not `preg_quote` tags when using xkey. Quoting is only used for BAN
12+
requests that expect a regular expression. This bug only affected you if you
13+
use xkey *and* used characters in your tags that are changed by `preg_quote`.
14+
615
2.3.0
716
-----
817

src/ProxyClient/Varnish.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ class Varnish extends HttpProxyClient implements BanCapable, PurgeCapable, Refre
7373
public function invalidateTags(array $tags)
7474
{
7575
$banMode = self::TAG_BAN === $this->options['tag_mode'];
76-
$escapedTags = array_map('preg_quote', $this->escapeTags($tags));
7776

78-
$chunkSize = $this->determineTagsPerHeader($escapedTags, $banMode ? '|' : ' ');
77+
// If using BAN's, escape each tag
78+
if ($banMode) {
79+
$tags = array_map('preg_quote', $this->escapeTags($tags));
80+
}
81+
82+
$chunkSize = $this->determineTagsPerHeader($tags, $banMode ? '|' : ' ');
7983

80-
foreach (array_chunk($escapedTags, $chunkSize) as $tagchunk) {
84+
foreach (array_chunk($tags, $chunkSize) as $tagchunk) {
8185
if ($banMode) {
8286
$this->invalidateByBan($tagchunk);
8387
} else {

tests/Unit/ProxyClient/VarnishTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,49 @@ function (RequestInterface $request) {
8484
$varnish->banPath('/articles/.*', 'text/html', $hosts);
8585
}
8686

87+
public function testPurgekeys()
88+
{
89+
$options = [
90+
'tag_mode' => 'purgekeys',
91+
];
92+
93+
$varnish = new Varnish($this->httpDispatcher, $options);
94+
$this->httpDispatcher->shouldReceive('invalidate')->once()->with(
95+
\Mockery::on(
96+
function (RequestInterface $request) {
97+
$this->assertEquals('PURGEKEYS', $request->getMethod());
98+
$this->assertEquals('post-1 post,type-3', $request->getHeaderLine('xkey-softpurge'));
99+
100+
return true;
101+
}
102+
), false
103+
);
104+
105+
$varnish->invalidateTags(['post-1', 'post,type-3']);
106+
}
107+
108+
public function testHardPurgekeys()
109+
{
110+
$options = [
111+
'tag_mode' => 'purgekeys',
112+
'tags_header' => 'xkey-purge',
113+
];
114+
115+
$varnish = new Varnish($this->httpDispatcher, $options);
116+
$this->httpDispatcher->shouldReceive('invalidate')->once()->with(
117+
\Mockery::on(
118+
function (RequestInterface $request) {
119+
$this->assertEquals('PURGEKEYS', $request->getMethod());
120+
$this->assertEquals('post-1 post,type-3', $request->getHeaderLine('xkey-purge'));
121+
122+
return true;
123+
}
124+
), false
125+
);
126+
127+
$varnish->invalidateTags(['post-1', 'post,type-3']);
128+
}
129+
87130
/**
88131
* @expectedException \FOS\HttpCache\Exception\InvalidArgumentException
89132
*/

0 commit comments

Comments
 (0)