Skip to content

Commit b185056

Browse files
committed
bug symfony#14802 [HttpKernel] fix broken multiline <esi:remove> (sstok)
This PR was squashed before being merged into the 2.3 branch (closes symfony#14802). Discussion ---------- [HttpKernel] fix broken multiline <esi:remove> |Q |A | |--- |---| |Bug Fix? |yes| |New Feature? |n | |BC Breaks? |n | |Deprecations?|n | |Tests Pass? |yes| |Fixed Tickets| | |License |MIT| |Doc PR | | Originally found in symfony#14800 (diff) `<esi:remove>` blocks with multiline contents were not removed. `<esi:comment>` blocks with multiline contents were not removed. Note. According to http://www.w3.org/TR/esi-lang `comment is an empty element, and must not have an end tag.` so the support for multi line comments are not actually supported in the standard. Commits ------- 06f97bf [HttpKernel] fix broken multiline <esi:remove>
2 parents dcc6581 + 06f97bf commit b185056

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Symfony/Component/HttpKernel/HttpCache/Esi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public function process(Request $request, Response $response)
162162

163163
// we don't use a proper XML parser here as we can have ESI tags in a plain text response
164164
$content = $response->getContent();
165-
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#', '', $content);
166-
$content = preg_replace('#<esi\:comment[^>]*(?:/|</esi\:comment)>#', '', $content);
165+
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#s', '', $content);
166+
$content = preg_replace('#<esi\:comment[^>]+>#s', '', $content);
167167

168168
$chunks = preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
169169
$chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);

src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ public function testProcessDoesNothingIfContentTypeIsNotHtml()
9292
$this->assertFalse($response->headers->has('x-body-eval'));
9393
}
9494

95+
public function testMultilineEsiRemoveTagsAreRemoved()
96+
{
97+
$esi = new Esi();
98+
99+
$request = Request::create('/');
100+
$response = new Response('<esi:remove> <a href="http://www.example.com">www.example.com</a> </esi:remove> Keep this'."<esi:remove>\n <a>www.example.com</a> </esi:remove> And this");
101+
$esi->process($request, $response);
102+
103+
$this->assertEquals(' Keep this And this', $response->getContent());
104+
}
105+
106+
public function testCommentTagsAreRemoved()
107+
{
108+
$esi = new Esi();
109+
110+
$request = Request::create('/');
111+
$response = new Response('<esi:comment text="some comment &gt;" /> Keep this');
112+
$esi->process($request, $response);
113+
114+
$this->assertEquals(' Keep this', $response->getContent());
115+
}
116+
95117
public function testProcess()
96118
{
97119
$esi = new Esi();

0 commit comments

Comments
 (0)