Verified Commit 9383c598 authored by Jess's avatar Jess
Browse files

Issue #3195583 by smokris, smustgrave, mohit.bansal623, xjm, quietone: Fix...

Issue #3195583 by smokris, smustgrave, mohit.bansal623, xjm, quietone: Fix warning when RSS feed includes markup with an empty srcset attribute

(cherry picked from commit 217797fb)
parent f7a7eba4
Loading
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -484,11 +484,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));
+1 −0
Original line number Diff line number Diff line
@@ -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) {