From 4a8ed62252e93674b294ce2e510476182e6a5f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Mon, 2 Dec 2024 00:56:49 +0700 Subject: [PATCH 1/3] Closes #7146: Remove preconnect tag --- inc/Engine/Media/Fonts/Frontend/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index 7f9c488c24..9041ad705e 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -183,7 +183,7 @@ private function remove_preconnect_and_prefetch( string $html ) { return $html; } - $pattern = '/]*)(?:rel=["\'](?:dns-prefetch|preconnect)["\'])(?:[^>]*)(?:href=["\'](?:https?:)?\/\/(?:fonts\.(?:googleapis|gstatic)\.com)["\'])(?:[^>]*)>/i'; + $pattern = '/]+[\s"\'])?rel\s*=\s*[\'"]((preconnect)|(dns-prefetch))[\'"]([^>]+)?\/?>/i'; $html = preg_replace( $pattern, '', $html ); From 125789c82c484f0747a2d6a86aa322046f01e2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Tue, 3 Dec 2024 22:50:11 +0700 Subject: [PATCH 2/3] Make regex less general --- inc/Engine/Media/Fonts/Frontend/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index 9041ad705e..1be648e10d 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -183,7 +183,7 @@ private function remove_preconnect_and_prefetch( string $html ) { return $html; } - $pattern = '/]+[\s"\'])?rel\s*=\s*[\'"]((preconnect)|(dns-prefetch))[\'"]([^>]+)?\/?>/i'; + $pattern = '/]*\bhref\s*=\s*[\'"](?:https?:)?\/\/(?:fonts\.(?:googleapis|gstatic)\.com)[\'"][^>]*\brel\s*=\s*[\'"](?:preconnect|dns-prefetch)[\'"][^>]*>/i'; $html = preg_replace( $pattern, '', $html ); From a0dce79c759b707f304b0f54f5a2ce08a334f212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Tue, 3 Dec 2024 23:04:53 +0700 Subject: [PATCH 3/3] Fix tests --- inc/Engine/Media/Fonts/Frontend/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index 1be648e10d..0a578de965 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -183,7 +183,7 @@ private function remove_preconnect_and_prefetch( string $html ) { return $html; } - $pattern = '/]*\bhref\s*=\s*[\'"](?:https?:)?\/\/(?:fonts\.(?:googleapis|gstatic)\.com)[\'"][^>]*\brel\s*=\s*[\'"](?:preconnect|dns-prefetch)[\'"][^>]*>/i'; + $pattern = '/]*\b(rel\s*=\s*[\'"](?:preconnect|dns-prefetch)[\'"]|href\s*=\s*[\'"](?:https?:)?\/\/(?:fonts\.(?:googleapis|gstatic)\.com)[\'"])[^>]*\b(rel\s*=\s*[\'"](?:preconnect|dns-prefetch)[\'"]|href\s*=\s*[\'"](?:https?:)?\/\/(?:fonts\.(?:googleapis|gstatic)\.com)[\'"])[^>]*>/i'; $html = preg_replace( $pattern, '', $html );