Loading core/lib/Drupal/Component/Utility/Html.php +3 −4 Original line number Diff line number Diff line Loading @@ -480,11 +480,10 @@ public static function transformRootRelativeUrlsToAbsolute($html, $scheme_and_ho // @see https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset // @see https://html.spec.whatwg.org/multipage/embedded-content.html#image-candidate-string $image_candidate_strings = explode(',', $node->getAttribute('srcset')); $image_candidate_strings = array_map('trim', $image_candidate_strings); for ($i = 0; $i < count($image_candidate_strings); $i++) { $image_candidate_string = $image_candidate_strings[$i]; $image_candidate_strings = array_filter(array_map('trim', $image_candidate_strings)); foreach ($image_candidate_strings as $key => $image_candidate_string) { if ($image_candidate_string[0] === '/' && $image_candidate_string[1] !== '/') { $image_candidate_strings[$i] = $scheme_and_host . $image_candidate_string; $image_candidate_strings[$key] = $scheme_and_host . $image_candidate_string; } } $node->setAttribute('srcset', implode(', ', $image_candidate_strings)); Loading core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,7 @@ public function providerTestTransformRootRelativeUrlsToAbsolute() { "$tag_name, srcset, $base_path: root-relative" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, {$base_path}root-relative 300w\">root-relative test</$tag_name>", 'http://example.com', "<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}root-relative 300w\">root-relative test</$tag_name>"], "$tag_name, srcset, $base_path: protocol-relative" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, //example.com{$base_path}protocol-relative 300w\">protocol-relative test</$tag_name>", 'http://example.com', FALSE], "$tag_name, srcset, $base_path: absolute" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}absolute 300w\">absolute test</$tag_name>", 'http://example.com', FALSE], "$tag_name, empty srcset" => ["<$tag_name srcset=\"\">empty test</$tag_name>", 'http://example.com', FALSE], ]; foreach (['href', 'poster', 'src', 'cite', 'data', 'action', 'formaction', 'about'] as $attribute) { Loading Loading
core/lib/Drupal/Component/Utility/Html.php +3 −4 Original line number Diff line number Diff line Loading @@ -480,11 +480,10 @@ public static function transformRootRelativeUrlsToAbsolute($html, $scheme_and_ho // @see https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset // @see https://html.spec.whatwg.org/multipage/embedded-content.html#image-candidate-string $image_candidate_strings = explode(',', $node->getAttribute('srcset')); $image_candidate_strings = array_map('trim', $image_candidate_strings); for ($i = 0; $i < count($image_candidate_strings); $i++) { $image_candidate_string = $image_candidate_strings[$i]; $image_candidate_strings = array_filter(array_map('trim', $image_candidate_strings)); foreach ($image_candidate_strings as $key => $image_candidate_string) { if ($image_candidate_string[0] === '/' && $image_candidate_string[1] !== '/') { $image_candidate_strings[$i] = $scheme_and_host . $image_candidate_string; $image_candidate_strings[$key] = $scheme_and_host . $image_candidate_string; } } $node->setAttribute('srcset', implode(', ', $image_candidate_strings)); Loading
core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,7 @@ public function providerTestTransformRootRelativeUrlsToAbsolute() { "$tag_name, srcset, $base_path: root-relative" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, {$base_path}root-relative 300w\">root-relative test</$tag_name>", 'http://example.com', "<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}root-relative 300w\">root-relative test</$tag_name>"], "$tag_name, srcset, $base_path: protocol-relative" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, //example.com{$base_path}protocol-relative 300w\">protocol-relative test</$tag_name>", 'http://example.com', FALSE], "$tag_name, srcset, $base_path: absolute" => ["<$tag_name srcset=\"http://example.com{$base_path}already-absolute 200w, http://example.com{$base_path}absolute 300w\">absolute test</$tag_name>", 'http://example.com', FALSE], "$tag_name, empty srcset" => ["<$tag_name srcset=\"\">empty test</$tag_name>", 'http://example.com', FALSE], ]; foreach (['href', 'poster', 'src', 'cite', 'data', 'action', 'formaction', 'about'] as $attribute) { Loading