Verified Commit 98df2c98 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3360220 by jeffschuler: Logic error in Html::transformRootRelativeUrlsToAbsolute()

parent 8fd17f42
Loading
Loading
Loading
Loading
Loading
+3 −1
Changes for core/lib/Drupal/Component/Utility/Html.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -472,10 +472,13 @@ public static function transformRootRelativeUrlsToAbsolute($html, $scheme_and_ho
    $xpath = new \DOMXpath($html_dom);

    // Update all root-relative URLs to absolute URLs in the given HTML.
    // Perform on attributes that may contain a single URI.
    foreach (static::$uriAttributes as $attr) {
      foreach ($xpath->query("//*[starts-with(@$attr, '/') and not(starts-with(@$attr, '//'))]") as $node) {
        $node->setAttribute($attr, $scheme_and_host . $node->getAttribute($attr));
      }
    }
    // Perform on each URI within "srcset" attributes.
    foreach ($xpath->query("//*[@srcset]") as $node) {
      // @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
@@ -489,7 +492,6 @@ public static function transformRootRelativeUrlsToAbsolute($html, $scheme_and_ho
      }
      $node->setAttribute('srcset', implode(', ', $image_candidate_strings));
    }
    }
    return Html::serialize($html_dom);
  }