Skip to content

Commit

Permalink
Match full domain path in src attr
Browse files Browse the repository at this point in the history
  • Loading branch information
markkelnar committed Jan 25, 2021
1 parent f2d0578 commit 3509488
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions plugins/wpe-headless/includes/replacement/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<img src="http://example.org">', wpe_headless_content_media_replacement( '<img src="http://foo.com">' ) );
# Do not replace partial domain main.
$this->assertSame( '<img src="http://foo.com/image.png">', wpe_headless_content_media_replacement( '<img src="http://foo.com/image.png">' ) );
$this->assertSame( '<img src="http://example.org/image.png">', wpe_headless_content_media_replacement( '<img src="http://foo.co/image.png">' ) );
wpe_headless_update_setting( 'frontend_uri', null );
remove_filter( 'wpe_headless_domain_replacement_enabled', '__return_true' );
}
Expand Down

0 comments on commit 3509488

Please sign in to comment.