Unverified Commit b43c49e6 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3174349 by quietone, itaran, dww, Kristen Pol:...

Issue #3174349 by quietone, itaran, dww, Kristen Pol: file_url_transform_relative() cannot handle URLs where the port is different from the site's request port
parent 346d176c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -126,6 +126,13 @@ function file_url_transform_relative($file_url) {
  $host = $request->getHost();
  $scheme = $request->getScheme();
  $port = $request->getPort() ?: 80;

  // Files may be accessible on a different port than the web request.
  $file_url_port = parse_url($file_url, PHP_URL_PORT) ?? $port;
  if ($file_url_port != $port) {
    return $file_url;
  }

  if (('http' == $scheme && $port == 80) || ('https' == $scheme && $port == 443)) {
    $http_host = $host;
  }
+50 −35
Original line number Diff line number Diff line
@@ -41,41 +41,56 @@ public function testFileUrlTransformRelative($host, $port, $https, $url, $expect
  }

  public function providerFileUrlTransformRelative() {
    $data = [];
    $data[] = [
    $data = [
      'http' => [
        'example.com',
        80,
        '',
        'http://example.com/page',
        '/page',
    ];
    $data[] = [
      ],
      'https' => [
        'example.com',
        443,
        'on',
        'https://example.com/page',
        '/page',
    ];
    $data[] = [
      ],
      'http 8080' => [
        'example.com',
        8080,
        '',
        'https://example.com:8080/page',
        '/page',
    ];
    $data[] = [
      ],
      'https 8443' => [
        'example.com',
        8443,
        'on',
        'https://example.com:8443/page',
        '/page',
    ];
    $data[] = [
      ],
      'http no dot' => [
        'example.com',
        80,
        '',
        'http://exampleXcom/page',
        'http://exampleXcom/page',
      ],
      'http files on different port than the web request' => [
        'example.com',
        80,
        '',
        'http://example.com:9000/page',
        'http://example.com:9000/page',
      ],
      'https files on different port than the web request' => [
        'example.com',
        443,
        'on',
        'https://example.com:8443/page',
        'https://example.com:8443/page',
      ],
    ];
    return $data;
  }