Commit 73d74826 authored by catch's avatar catch
Browse files

Issue #3554522 by alexpott: Only parse and mess with the URI in...

Issue #3554522 by alexpott: Only parse and mess with the URI in \Drupal\Core\Utility\UnroutedUrlAssembler::buildExternalUrl() if we have to
parent 185668ed
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ public function assemble($uri, array $options = [], $collect_bubbleable_metadata
   * {@inheritdoc}
   */
  protected function buildExternalUrl($uri, array $options = [], $collect_bubbleable_metadata = FALSE) {
    // Early return so external URLs are not altered unnecessarily.
    if (empty($options['query']) && empty($options['fragment']) && !isset($options['https'])) {
      return $collect_bubbleable_metadata ? (new GeneratedUrl())->setGeneratedUrl($uri) : $uri;
    }
    $this->addOptionDefaults($options);
    // Split off the query & fragment.
    $parsed = UrlHelper::parse($uri);
+16 −0
Original line number Diff line number Diff line
@@ -195,6 +195,22 @@ public function testAssembleWithStartingSlashEnabledProcessing(): void {
    $this->assertEquals($expected_generated_url, $result);
  }

  /**
   * Tests external URLs are only processed if necessary.
   *
   * @testWith ["http://example.org", "http://example.org"]
   *           ["http://example.org?flag", "http://example.org?flag"]
   *           ["http://example.org?flag=", "http://example.org?flag="]
   *           ["http://example.org?flag=", "http://example.org?flag", {"query": {"flag": ""}}]
   *           ["http://example.org?tag=one&tag=two", "http://example.org?tag=one&tag=two"]
   *           ["http://example.org?tag%5B0%5D=three", "http://example.org?tag=one&tag=two", {"query": {"tag": ["three"]}}]
   */
  public function testAssembleExternalUrls(string $expected, string $uri, array $options = []): void {
    $this->setupRequestStack(FALSE);
    $result = $this->unroutedUrlAssembler->assemble($uri, $options);
    $this->assertEquals($expected, $result);
  }

  /**
   * Setups the request stack for a given subdir.
   *