diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index ea98965..5f174b3 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -1390,7 +1390,8 @@ function _filter_html_image_secure_process($text) { // Remove absolute URLs pointing to the local domain to prevent mixed // content errors. $request = \Drupal::request(); - $image->setAttribute('src', preg_replace('|^https?://' . $request->getHost() . '|', '', $src)); + $port = $request->getPort(); + $image->setAttribute('src', preg_replace('|^https?://' . $request->getHost() . '(' . preg_quote(':' . $port) . ')?|', '', $src)); // Verify that $src starts with $base_path. // This also ensures that external images cannot be referenced. diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php index d61bfa1..b905a30 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php @@ -97,6 +97,8 @@ function testImageSource() { // expected filter conversions. $images = array( $http_base_url . '/' . $druplicon => base_path() . $druplicon, + // Test a url that includes the port. + $http_base_url . ':' . $this->container->get('request')->getPort() . base_path() . $druplicon => base_path() . $druplicon, $https_base_url . '/' . $druplicon => base_path() . $druplicon, base_path() . $druplicon => base_path() . $druplicon, $files_path . '/' . $test_image => $files_path . '/' . $test_image,