From 3509488093223e27335ecc2dd319835e73c1c070 Mon Sep 17 00:00:00 2001 From: Mark Kelnar Date: Mon, 25 Jan 2021 12:43:06 -0600 Subject: [PATCH] Match full domain path in src attr --- plugins/wpe-headless/includes/replacement/callbacks.php | 4 +--- .../integration/replacement/test-replacement-callbacks.php | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/wpe-headless/includes/replacement/callbacks.php b/plugins/wpe-headless/includes/replacement/callbacks.php index 3c0eb02df..0760c0600 100644 --- a/plugins/wpe-headless/includes/replacement/callbacks.php +++ b/plugins/wpe-headless/includes/replacement/callbacks.php @@ -56,9 +56,7 @@ function wpe_headless_content_media_replacement( $content ) { $frontend_uri = '/'; } - $content = str_replace( "src=\"{$frontend_uri}", "src=\"{$site_url}", $content ); - - return str_replace( 'src="//', 'src="/', $content ); + return str_replace( "src=\"{$frontend_uri}/", "src=\"{$site_url}/", $content ); } add_filter( 'preview_post_link', 'wpe_headless_post_preview_link', 10, 2 ); diff --git a/plugins/wpe-headless/tests/integration/replacement/test-replacement-callbacks.php b/plugins/wpe-headless/tests/integration/replacement/test-replacement-callbacks.php index b815c2904..2c595fce6 100644 --- a/plugins/wpe-headless/tests/integration/replacement/test-replacement-callbacks.php +++ b/plugins/wpe-headless/tests/integration/replacement/test-replacement-callbacks.php @@ -61,9 +61,11 @@ public function test_wpe_headless_content_replacement_filters_content_when_conte * Tests wpe_headless_content_media_replacement() replaces the frontend_uri value when content replacement is enabled. */ public function test_wpe_headless_content_media_replacement_filters_content_when_content_replacement_enabled() { - wpe_headless_update_setting( 'frontend_uri', 'http://foo.com' ); + wpe_headless_update_setting( 'frontend_uri', 'http://foo.co' ); add_filter( 'wpe_headless_domain_replacement_enabled', '__return_true' ); - $this->assertSame( '', wpe_headless_content_media_replacement( '' ) ); + # Do not replace partial domain main. + $this->assertSame( '', wpe_headless_content_media_replacement( '' ) ); + $this->assertSame( '', wpe_headless_content_media_replacement( '' ) ); wpe_headless_update_setting( 'frontend_uri', null ); remove_filter( 'wpe_headless_domain_replacement_enabled', '__return_true' ); }