From a7faa8701fb81a6dc0f544bfb65925657879290a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 17 Dec 2024 13:25:27 -0500 Subject: [PATCH 1/4] check exclusion against the whole tag --- inc/Engine/Media/Fonts/Frontend/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/Engine/Media/Fonts/Frontend/Controller.php b/inc/Engine/Media/Fonts/Frontend/Controller.php index ef22405e8f..9f3fa5c807 100644 --- a/inc/Engine/Media/Fonts/Frontend/Controller.php +++ b/inc/Engine/Media/Fonts/Frontend/Controller.php @@ -99,14 +99,14 @@ private function rewrite_fonts( $html ): string { $total_fonts = $total_v1 + $total_v2; foreach ( $v1_fonts as $font ) { - if ( $this->is_excluded( $font['url'], $exclusions ) ) { + if ( $this->is_excluded( $font[0], $exclusions ) ) { continue; } $html = $this->replace_font( $font, $html ); } foreach ( $v2_fonts as $font ) { - if ( $this->is_excluded( $font['url'], $exclusions ) ) { + if ( $this->is_excluded( $font[0], $exclusions ) ) { continue; } $html = $this->replace_font( $font, $html ); From 7806568356b98ebaede1aa026c1a7e7efb2c488f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 17 Dec 2024 13:26:25 -0500 Subject: [PATCH 2/4] update method declaration --- inc/Engine/Media/Fonts/FontsTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/Engine/Media/Fonts/FontsTrait.php b/inc/Engine/Media/Fonts/FontsTrait.php index 52febbeaf0..e669114488 100644 --- a/inc/Engine/Media/Fonts/FontsTrait.php +++ b/inc/Engine/Media/Fonts/FontsTrait.php @@ -22,14 +22,14 @@ protected function get_exclusions(): array { } /** - * Checks if a URL is excluded based on the provided exclusions. + * Checks if a font is excluded based on the provided exclusions. * - * @param string $url The URL to check. + * @param string $subject The string to check. * @param string[] $exclusions The list of exclusions. * * @return bool True if the URL is excluded, false otherwise. */ - protected function is_excluded( string $url, array $exclusions ): bool { + protected function is_excluded( string $subject, array $exclusions ): bool { // Bail out early if there are no exclusions. if ( empty( $exclusions ) ) { return false; @@ -53,6 +53,6 @@ function ( $exclusion ) { $exclusions_str = implode( '|', $escaped_exclusions ); // Check the URL against the combined regex pattern. - return (bool) preg_match( '#(' . $exclusions_str . ')#i', $url ); + return (bool) preg_match( '#(' . $exclusions_str . ')#i', $subject ); } } From 6e47819c0e1e2d72158427946f30b77b249763aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 17 Dec 2024 13:37:32 -0500 Subject: [PATCH 3/4] update fixture based on AC --- .../Fonts/Frontend/Subscriber/HTML/expected_v1_v2_regex.php | 1 + .../Media/Fonts/Frontend/Subscriber/HTML/input_v1_v2_regex.php | 1 + .../Fonts/Frontend/Subscriber/rewriteFontsForOptimizations.php | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Fixtures/inc/Engine/Media/Fonts/Frontend/Subscriber/HTML/expected_v1_v2_regex.php b/tests/Fixtures/inc/Engine/Media/Fonts/Frontend/Subscriber/HTML/expected_v1_v2_regex.php index 61749557f7..0d2c2d2350 100644 --- a/tests/Fixtures/inc/Engine/Media/Fonts/Frontend/Subscriber/HTML/expected_v1_v2_regex.php +++ b/tests/Fixtures/inc/Engine/Media/Fonts/Frontend/Subscriber/HTML/expected_v1_v2_regex.php @@ -12,6 +12,7 @@ +