You are here

public function UrlHelperTest::providerTestExternalIsLocal in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php \Drupal\Tests\Component\Utility\UrlHelperTest::providerTestExternalIsLocal()
  2. 10 core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php \Drupal\Tests\Component\Utility\UrlHelperTest::providerTestExternalIsLocal()

Provider for local external url detection.

See also

\Drupal\Tests\Component\Utility\UrlHelperTest::testExternalIsLocal()

File

core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php, line 577

Class

UrlHelperTest
@group Utility

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestExternalIsLocal() {
  return [
    // Different mixes of trailing slash.
    [
      'http://example.com',
      'http://example.com',
      TRUE,
    ],
    [
      'http://example.com/',
      'http://example.com',
      TRUE,
    ],
    [
      'http://example.com',
      'http://example.com/',
      TRUE,
    ],
    [
      'http://example.com/',
      'http://example.com/',
      TRUE,
    ],
    // Sub directory of site.
    [
      'http://example.com/foo',
      'http://example.com/',
      TRUE,
    ],
    [
      'http://example.com/foo/bar',
      'http://example.com/foo',
      TRUE,
    ],
    [
      'http://example.com/foo/bar',
      'http://example.com/foo/',
      TRUE,
    ],
    // Different sub-domain.
    [
      'http://example.com',
      'http://www.example.com/',
      FALSE,
    ],
    [
      'http://example.com/',
      'http://www.example.com/',
      FALSE,
    ],
    [
      'http://example.com/foo',
      'http://www.example.com/',
      FALSE,
    ],
    // Different TLD.
    [
      'http://example.com',
      'http://example.ca',
      FALSE,
    ],
    [
      'http://example.com',
      'http://example.ca/',
      FALSE,
    ],
    [
      'http://example.com/',
      'http://example.ca/',
      FALSE,
    ],
    [
      'http://example.com/foo',
      'http://example.ca',
      FALSE,
    ],
    [
      'http://example.com/foo',
      'http://example.ca/',
      FALSE,
    ],
    // Different site path.
    [
      'http://example.com/foo',
      'http://example.com/bar',
      FALSE,
    ],
    [
      'http://example.com',
      'http://example.com/bar',
      FALSE,
    ],
    [
      'http://example.com/bar',
      'http://example.com/bar/',
      FALSE,
    ],
    // Ensure \ is normalized to / since some browsers do that.
    [
      'http://www.example.ca\\@example.com',
      'http://example.com',
      FALSE,
    ],
    // Some browsers ignore or strip leading control characters.
    [
      "\0//www.example.ca",
      'http://example.com',
      FALSE,
    ],
  ];
}