Commit f95fc93c authored by alexpott's avatar alexpott

Issue #2678662 by Wim Leers, mondrake, Fabianx, alexpott: Ensure BigPipe does...

Issue #2678662 by Wim Leers, mondrake, Fabianx, alexpott: Ensure BigPipe does not break when HTML document contains CDATA sections or inline scripts matching certain patterns
parent 046d1a41
......@@ -126,7 +126,13 @@ public function sendContent($content, array $attachments) {
// Reopen it for the duration that we are rendering placeholders.
list($pre_body, $post_body) = explode('</body>', $content, 2);
// Find the closing </body> tag and get the strings before and after. But be
// careful to use the latest occurrence of the string "</body>", to ensure
// that strings in inline JavaScript or CDATA sections aren't used instead.
$parts = explode('</body>', $content);
$post_body = array_pop($parts);
$pre_body = implode('', $parts);
$this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets);
$this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body), $cumulative_assets);
name: 'BigPipe regression test'
type: module
description: 'Support module for BigPipe regression testing.'
package: Testing
version: VERSION
core: 8.x
path: '/big_pipe_regression_test/2678662'
_controller: '\Drupal\big_pipe_regression_test\BigPipeRegressionTestController::regression2678662'
_access: 'TRUE'
namespace Drupal\big_pipe_regression_test;
use Drupal\big_pipe\Render\BigPipeMarkup;
class BigPipeRegressionTestController {
const MARKER_2678662 = '<script>var hitsTheFloor = "</body>";</script>';
* @see \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleBodies_2678662()
public function regression2678662() {
return [
'#markup' => BigPipeMarkup::create(self::MARKER_2678662),
......@@ -2,10 +2,13 @@
namespace Drupal\Tests\big_pipe\FunctionalJavascript;
use Drupal\big_pipe\Render\BigPipe;
use Drupal\big_pipe_regression_test\BigPipeRegressionTestController;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Url;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
......@@ -30,6 +33,7 @@ class BigPipeRegressionTest extends JavascriptTestBase {
......@@ -114,4 +118,29 @@ public function testCommentForm_2698811() {
* Ensure BigPipe works despite inline JS containing the string "</body>".
* @see
public function testMultipleClosingBodies_2678662() {
// Confirm that AJAX behaviors were instantiated, if not, this points to a
// JavaScript syntax error.
$javascript = <<<JS
return Object.keys(Drupal.ajax.instances).length > 0;
// Besides verifying there is no JavaScript syntax error, also verify the
// HTML structure.
$this->assertSession()->responseContains(BigPipe::STOP_SIGNAL . "\n\n\n</body></html>", 'The BigPipe stop signal is present just before the closing </body> and </html> tags.');
$js_code_until_closing_body_tag = substr(BigPipeRegressionTestController::MARKER_2678662, 0, strpos(BigPipeRegressionTestController::MARKER_2678662, '</body>'));
$this->assertSession()->responseNotContains($js_code_until_closing_body_tag . "\n" . BigPipe::START_SIGNAL, 'The BigPipe start signal does NOT start at the closing </body> tag string in an inline script.');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment