Skip to content

Commit

Permalink
:closes: #6960 Fix issue with multiple body tag in the page
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jan 16, 2025
1 parent e726c3d commit 12c65f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/Engine/Common/PerformanceHints/Frontend/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function inject_beacon( $html, $url, $is_mobile ): string {
$script_tag = "<script data-name=\"wpr-wpr-beacon\" src='{$script_url}' async></script>"; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript

// Append the script tag just before the closing body tag.
return str_replace( '</body>', $inline_script . $script_tag . '</body>', $html );
return preg_replace( '/<\/body>/', $inline_script . $script_tag . '</body>', $html, 1 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>Test</title>
</head>
<body>
<script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

$html_input = file_get_contents(__DIR__ . '/HTML/input.html');
$html_with_double_body = file_get_contents(__DIR__ . '/HTML/double_body_tag.html');
$html_with_double_body_output = file_get_contents(__DIR__ . '/HTML/output_double_body_tag.html');
$html_output = file_get_contents(__DIR__ . '/HTML/output.html');
$html_output_with_preload = file_get_contents(__DIR__ . '/HTML/output_w_preload.html');
$html_output_with_beacon = file_get_contents(__DIR__ . '/HTML/output_w_beacon.html');
Expand Down Expand Up @@ -615,5 +617,17 @@
],
'expected' => $html_output_with_beacon_and_only_lrc_opt,
],
'shouldNotDuplicateBeaconOnAPage' => [
'config' => [
'html' => $html_with_double_body,
'atf' => [
'row' => null,
],
'lrc' => [
'row' => null,
],
],
'expected' => $html_with_double_body_output,
],
],
];

0 comments on commit 12c65f1

Please sign in to comment.