bug #14802 [HttpKernel] fix broken multiline <esi:remove> (sstok)

This PR was squashed before being merged into the 2.3 branch (closes #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 https://github.com/symfony/symfony/pull/14800#discussion-diff-31388942

`<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>
This commit is contained in:
Fabien Potencier 2015-09-14 09:14:59 +02:00
commit b185056776
2 changed files with 24 additions and 2 deletions

View File

@ -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('#<esi\:remove>.*?</esi\:remove>#', '', $content);
$content = preg_replace('#<esi\:comment[^>]*(?:/|</esi\:comment)>#', '', $content);
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#s', '', $content);
$content = preg_replace('#<esi\:comment[^>]+>#s', '', $content);
$chunks = preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
$chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);

View File

@ -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('<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");
$esi->process($request, $response);
$this->assertEquals(' Keep this And this', $response->getContent());
}
public function testCommentTagsAreRemoved()
{
$esi = new Esi();
$request = Request::create('/');
$response = new Response('<esi:comment text="some comment &gt;" /> Keep this');
$esi->process($request, $response);
$this->assertEquals(' Keep this', $response->getContent());
}
public function testProcess()
{
$esi = new Esi();