Skip to content

Commit

Permalink
Fixes #6910 regex to remove data mismatch (#6915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal authored Aug 29, 2024
1 parent 30fb031 commit 17485ca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function optimize( string $html, $row ): string {
* @return string
*/
private function remove_hashes( $html ) {
$result = preg_replace( '/data-rocket-location-hash="(?:.*)"/i', '', $html );
$result = preg_replace( '/data-rocket-location-hash="[^"]*"/i', '', $html );

if ( null === $result ) {
return $html;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>Single line element</title>
<style id="rocket-lazyrender-inline-css">[data-wpr-lazyrender] {content-visibility: auto;}</style>
</head>
<body>
<div data-wpr-lazyrender="1"> div in body <div data-wpr-lazyrender="1"> another div in body <header data-wpr-lazyrender="1"> header in div in div in body<div>another div in header in div in div in body</div></header></div></div>
<footer >
<div >
<p>Original footer</p>
</div>
</footer>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

$hashed = file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/hashed.html' );
$expected = file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/expected.html' );
$single_line_hashed = file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/single-line-hashed.html' );
$single_line_expected = file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller/expected-single-line.html' );

return [
'testShouldReturnEarlyWhenNoDbEntry' => [
Expand Down Expand Up @@ -36,4 +38,12 @@
'html' => $hashed,
'expected' => $expected,
],
'testShouldReturnUpdatedHtmlForSingleLine' => [
'config' => [
'has_lrc' => true,
'below_the_fold' => json_encode( [ '7b16eca0652d4703f83ba63e304f2030', '30c5235261141d2450dc033e5c78bbcc', 'b42afa69f728fcc707157eb61efa53cc' ] ),
],
'html' => $single_line_hashed,
'expected' => $single_line_expected,
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<title>Single line element</title>
</head>
<body>
<div data-rocket-location-hash="7b16eca0652d4703f83ba63e304f2030"> div in body <div data-rocket-location-hash="30c5235261141d2450dc033e5c78bbcc"> another div in body <header data-rocket-location-hash="b42afa69f728fcc707157eb61efa53cc"> header in div in div in body<div>another div in header in div in div in body</div></header></div></div>
<footer data-rocket-location-hash="daf185c1c5cd6ae65d6a3b0721be5714">
<div data-rocket-location-hash="57f84b25dc0def2056eb68ae21a02316">
<p>Original footer</p>
</div>
</footer>
</body>
</html>

0 comments on commit 17485ca

Please sign in to comment.