diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php
index bc55bed51a..28270ed5d3 100644
--- a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php
+++ b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php
@@ -162,8 +162,8 @@ class Esi
// we don't use a proper XML parser here as we can have ESI tags in a plain text response
$content = $response->getContent();
- $content = preg_replace('#.*?#', '', $content);
- $content = preg_replace('#]*(?:/|#', '', $content);
+ $content = preg_replace('#.*?#s', '', $content);
+ $content = preg_replace('#]+>#s', '', $content);
$chunks = preg_split('##', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);
diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php
index d1411f016b..e83996c2e2 100644
--- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/EsiTest.php
@@ -92,6 +92,28 @@ class EsiTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($response->headers->has('x-body-eval'));
}
+ public function testMultilineEsiRemoveTagsAreRemoved()
+ {
+ $esi = new Esi();
+
+ $request = Request::create('/');
+ $response = new Response(' www.example.com Keep this'."\n www.example.com And this");
+ $esi->process($request, $response);
+
+ $this->assertEquals(' Keep this And this', $response->getContent());
+ }
+
+ public function testCommentTagsAreRemoved()
+ {
+ $esi = new Esi();
+
+ $request = Request::create('/');
+ $response = new Response(' Keep this');
+ $esi->process($request, $response);
+
+ $this->assertEquals(' Keep this', $response->getContent());
+ }
+
public function testProcess()
{
$esi = new Esi();