Skip to content
Snippets Groups Projects
Verified Commit 8165b07e authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2983058 by arnested, smustgrave, larowlan:...

Issue #2983058 by arnested, smustgrave, larowlan: FileUrlGenerator::transformRelative() edge case errors

(cherry picked from commit 9fecb4b6)
parent 5c3083ef
Branches
Tags
16 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core
Pipeline #67322 passed with warnings
Pipeline: drupal

#67358

    Pipeline: drupal

    #67355

      Pipeline: drupal

      #67352

        +6
        ......@@ -211,7 +211,6 @@ public function transformRelative(string $file_url, bool $root_relative = TRUE):
        // instead of a port number.
        $request = $this->requestStack->getCurrentRequest();
        $host = $request->getHost();
        $scheme = $request->getScheme();
        $port = $request->getPort() ?: 80;
        // Files may be accessible on a different port than the web request.
        ......@@ -220,20 +219,15 @@ public function transformRelative(string $file_url, bool $root_relative = TRUE):
        return $file_url;
        }
        if (('http' == $scheme && $port == 80) || ('https' == $scheme && $port == 443)) {
        $http_host = $host;
        }
        else {
        $http_host = $host . ':' . $port;
        }
        // If this should not be a root-relative path but relative to the drupal
        // base path, add it to the host to be removed from the URL as well.
        if (!$root_relative) {
        $http_host .= $request->getBasePath();
        }
        $base_path = !$root_relative ? $request->getBasePath() : '';
        $host = preg_quote($host, '@');
        $port = preg_quote($port, '@');
        $base_path = preg_quote($base_path, '@');
        return preg_replace('|^https?://' . preg_quote($http_host, '|') . '|', '', $file_url);
        return preg_replace("@^https?://{$host}(:{$port})?{$base_path}($|/)@", '/', $file_url);
        }
        }
        ......@@ -19,25 +19,25 @@ class UrlTransformRelativeTest extends KernelTestBase {
        *
        * @dataProvider providerFileUrlTransformRelative
        */
        public function testFileUrlTransformRelative($host, $port, $https, $url, $expected) {
        public function testFileUrlTransformRelative($host, $port, $https, $base_path, $root_relative, $url, $expected) {
        $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
        $_SERVER['SERVER_ADDR'] = '127.0.0.1';
        $_SERVER['SERVER_PORT'] = $port;
        $_SERVER['SERVER_SOFTWARE'] = NULL;
        $_SERVER['SERVER_NAME'] = $host;
        $_SERVER['REQUEST_URI'] = '/';
        $_SERVER['REQUEST_URI'] = "{$base_path}/";
        $_SERVER['REQUEST_METHOD'] = 'GET';
        $_SERVER['SCRIPT_NAME'] = '/index.php';
        $_SERVER['SCRIPT_FILENAME'] = '/index.php';
        $_SERVER['PHP_SELF'] = '/index.php';
        $_SERVER['SCRIPT_NAME'] = "{$base_path}/index.php";
        $_SERVER['SCRIPT_FILENAME'] = "{$base_path}/index.php";
        $_SERVER['PHP_SELF'] = "{$base_path}/index.php";
        $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
        $_SERVER['HTTPS'] = $https;
        $request = Request::createFromGlobals();
        \Drupal::requestStack()->push($request);
        $this->assertSame($expected, \Drupal::service('file_url_generator')->transformRelative($url));
        $this->assertSame($expected, \Drupal::service('file_url_generator')->transformRelative($url, $root_relative));
        }
        public function providerFileUrlTransformRelative() {
        ......@@ -46,20 +46,116 @@ public function providerFileUrlTransformRelative() {
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com/page',
        '/page',
        ],
        'http with base path and root relative' => [
        'example.com',
        80,
        '',
        '/~foo',
        TRUE,
        'http://example.com/~foo/page',
        '/~foo/page',
        ],
        'http with base path and not root relative' => [
        'example.com',
        80,
        '',
        '/~foo',
        FALSE,
        'http://example.com/~foo/page',
        '/page',
        ],
        'http with weird base path and root relative' => [
        'example.com',
        80,
        '',
        '/~foo$.*!',
        TRUE,
        'http://example.com/~foo$.*!/page',
        '/~foo$.*!/page',
        ],
        'http with weird base path and not root relative' => [
        'example.com',
        80,
        '',
        '/~foo$.*!',
        FALSE,
        'http://example.com/~foo$.*!/page',
        '/page',
        ],
        'http frontpage' => [
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com',
        '/',
        ],
        'http frontpage with a slash' => [
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com/',
        '/',
        ],
        'https on http' => [
        'example.com',
        80,
        '',
        '',
        TRUE,
        'https://example.com/page',
        '/page',
        ],
        'https' => [
        'example.com',
        443,
        'on',
        '',
        TRUE,
        'https://example.com/page',
        '/page',
        ],
        'https frontpage' => [
        'example.com',
        443,
        'on',
        '',
        TRUE,
        'https://example.com',
        '/',
        ],
        'https frontpage with a slash' => [
        'example.com',
        443,
        'on',
        '',
        TRUE,
        'https://example.com/',
        '/',
        ],
        'http with path containing special chars' => [
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com/~page$.*!',
        '/~page$.*!',
        ],
        'http 8080' => [
        'example.com',
        8080,
        '',
        '',
        TRUE,
        'https://example.com:8080/page',
        '/page',
        ],
        ......@@ -67,6 +163,8 @@ public function providerFileUrlTransformRelative() {
        'example.com',
        8443,
        'on',
        '',
        TRUE,
        'https://example.com:8443/page',
        '/page',
        ],
        ......@@ -74,6 +172,8 @@ public function providerFileUrlTransformRelative() {
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://exampleXcom/page',
        'http://exampleXcom/page',
        ],
        ......@@ -81,6 +181,8 @@ public function providerFileUrlTransformRelative() {
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com:9000/page',
        'http://example.com:9000/page',
        ],
        ......@@ -88,9 +190,47 @@ public function providerFileUrlTransformRelative() {
        'example.com',
        443,
        'on',
        '',
        TRUE,
        'https://example.com:8443/page',
        'https://example.com:8443/page',
        ],
        'http files on different port than the web request on non default port' => [
        'example.com',
        8080,
        '',
        '',
        TRUE,
        'http://example.com:9000/page',
        'http://example.com:9000/page',
        ],
        'https files on different port than the web request on non default port' => [
        'example.com',
        8443,
        'on',
        '',
        TRUE,
        'https://example.com:9000/page',
        'https://example.com:9000/page',
        ],
        'http with default port explicit mentioned in URL' => [
        'example.com',
        80,
        '',
        '',
        TRUE,
        'http://example.com:80/page',
        '/page',
        ],
        'https with default port explicit mentioned in URL' => [
        'example.com',
        443,
        'on',
        '',
        TRUE,
        'https://example.com:443/page',
        '/page',
        ],
        ];
        return $data;
        }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment