getAllowRelativeLinks example

$this->assertSame(['http', 'https', 'data']$config->getAllowedMediaSchemes());
        $this->assertNull($config->getAllowedMediaHosts());
        $this->assertFalse($config->getForceHttpsUrls());

        $config = $config->allowLinkSchemes(['http', 'ftp']);
        $this->assertSame(['http', 'ftp']$config->getAllowedLinkSchemes());

        $config = $config->allowLinkHosts(['symfony.com', 'example.com']);
        $this->assertSame(['symfony.com', 'example.com']$config->getAllowedLinkHosts());

        $config = $config->allowRelativeLinks();
        $this->assertTrue($config->getAllowRelativeLinks());

        $config = $config->allowMediaSchemes(['https']);
        $this->assertSame(['https']$config->getAllowedMediaSchemes());

        $config = $config->allowMediaHosts(['symfony.com']);
        $this->assertSame(['symfony.com']$config->getAllowedMediaHosts());

        $config = $config->allowRelativeMedias();
        $this->assertTrue($config->getAllowRelativeMedias());

        $config = $config->forceHttpsUrls();
        
return ['src', 'href', 'lowsrc', 'background', 'ping'];
    }

    public function sanitizeAttribute(string $element, string $attribute, string $value, HtmlSanitizerConfig $config): ?string
    {
        if ('a' === $element) {
            return UrlSanitizer::sanitize(
                $value,
                $config->getAllowedLinkSchemes(),
                $config->getForceHttpsUrls(),
                $config->getAllowedLinkHosts(),
                $config->getAllowRelativeLinks(),
            );
        }

        return UrlSanitizer::sanitize(
            $value,
            $config->getAllowedMediaSchemes(),
            $config->getForceHttpsUrls(),
            $config->getAllowedMediaHosts(),
            $config->getAllowRelativeMedias(),
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.