diff --git a/inc/url_replacer.php b/inc/url_replacer.php index 645b5bf2..12f3ecb2 100644 --- a/inc/url_replacer.php +++ b/inc/url_replacer.php @@ -95,6 +95,9 @@ public function build_image_url( $url = str_replace( array_keys( $this->site_mappings ), array_values( $this->site_mappings ), $url ); } + if ( substr( $url, 0, 2 ) === '//' ) { + $url = sprintf( '%s:%s', is_ssl() ? 'https' : 'http', $url ); + } $new_url = $this->strip_image_size_from_url( $url ); if ( $new_url !== $url ) { diff --git a/tests/test-replacer.php b/tests/test-replacer.php index 5eb29326..67398910 100644 --- a/tests/test-replacer.php +++ b/tests/test-replacer.php @@ -125,6 +125,19 @@ public function test_replacement_non_whitelisted_urls() { $this->assertContains( 'https://www.codeinwp.org', $replaced_content ); } + // TODO We need to extend this to single url replacement. If we make the url extractor regex with option scheme, the parsing will take huge amount of time. We need to think alternatives. + public function test_replacement_without_scheme() { + $content = ''; + $replaced_content = Optml_Manager::instance()->replace_content( $content ); + $this->assertContains( 'i.optimole.com', $replaced_content ); + $this->assertContains( 'http://www.example.org', $replaced_content );; + } + public function test_non_allowed_extensions() { $replaced_content = Optml_Manager::instance()->replace_content( ( self::CSS_STYLE . self::IMG_TAGS . self::WRONG_EXTENSION ) ); $this->assertContains( 'i.optimole.com', $replaced_content );