function UrlHelperTest::providerTestExternalIsLocal

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php \Drupal\Tests\Component\Utility\UrlHelperTest::providerTestExternalIsLocal()
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php \Drupal\Tests\Component\Utility\UrlHelperTest::providerTestExternalIsLocal()
  3. 11.x 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 610

Class

UrlHelperTest
@group Utility

Namespace

Drupal\Tests\Component\Utility

Code

public static 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.
[
            "\x00//www.example.ca",
            'http://example.com',
            FALSE,
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.