Skip to content

Commit 09a1e0a

Browse files
PeteLawrencedbu
authored andcommitted
Update X-Cache-Tags pattern to prevent objects being invalidated when their tag ends with the tag being invalidated (#404)
1 parent 2e75cd7 commit 09a1e0a

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

CHANGELOG.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ Changelog
33

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

6+
2.1.1
7+
-----
8+
9+
### Varnish
10+
11+
* Updated X-Cache-Tags regex to prevent matching partial tags
12+
13+
Invalidating objects with a tag of 'bar' would have previously also have
14+
invalidated objects with a tag that ends in 'bar', eg. 'foobar'. Now when
15+
invalidating an object the tag name must match in full.
16+
617
2.1.0
718
-----
819

@@ -51,27 +62,27 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
5162

5263
### HTTP
5364

54-
* **BC break:** Replaced hard coupling on Guzzle HTTP client with HTTPlug.
65+
* **BC break:** Replaced hard coupling on Guzzle HTTP client with HTTPlug.
5566
You now need to explicitly specify a supported HTTP adapter in composer.json;
5667
see [installation instructions](http://foshttpcache.readthedocs.io/en/stable/installation.html).
57-
* **BC break:** Separated the HttpDispatcher from the proxy clients. All
68+
* **BC break:** Separated the HttpDispatcher from the proxy clients. All
5869
existing clients still use HTTP to send invalidation requests.
5970
* Added support and documentation for setting a custom TTL specifically for the
6071
caching proxy.
6172

6273
### Logging
6374

64-
* **BC break:** Renamed the log event listener from `LogSubscriber` to
75+
* **BC break:** Renamed the log event listener from `LogSubscriber` to
6576
`LogListener`.
66-
77+
6778
### Proxy clients
6879

69-
* **BC break**: Renamed the `Ban`, `Purge`, `Refresh` and `Tag` interfaces to
80+
* **BC break**: Renamed the `Ban`, `Purge`, `Refresh` and `Tag` interfaces to
7081
`BanCapable`, `PurgeCapable`, `RefreshCapable` and `TagCapable`.
7182

7283
### Tagging
7384

74-
* **BC break:** Moved tag invalidation to `CacheInvalidator`, and renamed
85+
* **BC break:** Moved tag invalidation to `CacheInvalidator`, and renamed
7586
`TagHandler` to `ResponseTagger`.
7687
* Abstracting tags by adding new `TagCapable` for ProxyClients.
7788
* Added `strict` option to `ResponseTagger` that throws an exception when empty
@@ -97,21 +108,21 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
97108

98109
### Symfony HttpCache
99110

100-
* **BC break:** Renamed all event listeners to `XxListener` instead of
111+
* **BC break:** Renamed all event listeners to `XxListener` instead of
101112
`XxSubscriber`.
102-
* **BC break:** Constructors for `PurgeListener` and `RefreshListener` now use
113+
* **BC break:** Constructors for `PurgeListener` and `RefreshListener` now use
103114
an options array for customization.
104-
* **BC break:** Converted abstract event dispatching kernel class
115+
* **BC break:** Converted abstract event dispatching kernel class
105116
`EventDispatchingHttpCache` to a trait, which now provides the `addSubscriber`
106-
and `addListener` methods. In your `AppCache`, replace
107-
`AppCache extends EventDispatchingHttpInterface` with a
108-
`use EventDispatchingHttpCache;` statement.
117+
and `addListener` methods. In your `AppCache`, replace
118+
`AppCache extends EventDispatchingHttpInterface` with a
119+
`use EventDispatchingHttpCache;` statement.
109120
* The user context by default does not use a hardcoded hash for anonymous users
110121
but does a hash lookup. You can still configure a hardcoded hash.
111122

112123
### Testing
113124

114-
* **BC break:** Refactored the proxy client test system into traits. Removed
125+
* **BC break:** Refactored the proxy client test system into traits. Removed
115126
`ProxyTestCase`; use the traits `CacheAssertions` and `HttpCaller` instead.
116127
* Added HTTP method parameter to `HttpCaller::getResponse()`.
117128

src/ProxyClient/Varnish.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function invalidateTags(array $tags)
6666
$chunkSize = $this->determineTagsPerHeader($escapedTags, '|');
6767

6868
foreach (array_chunk($escapedTags, $chunkSize) as $tagchunk) {
69-
$tagExpression = sprintf('(%s)(,|$)', implode('|', $tagchunk));
69+
$tagExpression = sprintf('(^|,)(%s)(,|$)', implode('|', $tagchunk));
7070
$this->ban([$this->options['tags_header'] => $tagExpression]);
7171
}
7272

tests/Unit/ProxyClient/VarnishTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testTagsHeaders()
109109
\Mockery::on(
110110
function (RequestInterface $request) {
111111
$this->assertEquals('BAN', $request->getMethod());
112-
$this->assertEquals('(mytag|othertag)(,|$)', $request->getHeaderLine('X-Cache-Tags'));
112+
$this->assertEquals('(^|,)(mytag|othertag)(,|$)', $request->getHeaderLine('X-Cache-Tags'));
113113

114114
// That default BANs is taken into account also for tags as they are powered by BAN in this client.
115115
$this->assertEquals('.*', $request->getHeaderLine('Test'));
@@ -134,7 +134,7 @@ public function testTagsHeadersEscapingAndCustomHeader()
134134
\Mockery::on(
135135
function (RequestInterface $request) {
136136
$this->assertEquals('BAN', $request->getMethod());
137-
$this->assertEquals('(post\-1|post_type\-3)(,|$)', $request->getHeaderLine('X-Tags-TRex'));
137+
$this->assertEquals('(^|,)(post\-1|post_type\-3)(,|$)', $request->getHeaderLine('X-Tags-TRex'));
138138

139139
return true;
140140
}

0 commit comments

Comments
 (0)