From 06f97bfbd175ad681492176533cfe5611259b6b8 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Sun, 31 May 2015 13:21:21 +0200 Subject: [PATCH] [HttpKernel] fix broken multiline --- .../Component/HttpKernel/HttpCache/Esi.php | 4 ++-- .../HttpKernel/Tests/HttpCache/EsiTest.php | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php index 58b6265656..8242bfadcf 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();