getAllowedLinkHosts example


        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(),
        );
    }
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
use Symfony\Component\HtmlSanitizer\Visitor\AttributeSanitizer\AttributeSanitizerInterface;

class HtmlSanitizerConfigTest extends TestCase
{
    public function testCreateEmpty()
    {
        $config = new HtmlSanitizerConfig();
        $this->assertSame([]$config->getAllowedElements());
        $this->assertSame([]$config->getBlockedElements());
        $this->assertSame(['http', 'https', 'mailto', 'tel']$config->getAllowedLinkSchemes());
        $this->assertNull($config->getAllowedLinkHosts());
        $this->assertSame(['http', 'https', 'data']$config->getAllowedMediaSchemes());
        $this->assertNull($config->getAllowedMediaHosts());
        $this->assertFalse($config->getForceHttpsUrls());
    }

    public function testSimpleOptions()
    {
        $config = new HtmlSanitizerConfig();
        $this->assertSame(['http', 'https', 'mailto', 'tel']$config->getAllowedLinkSchemes());
        $this->assertNull($config->getAllowedLinkHosts());
        $this->assertSame(['http', 'https', 'data']$config->getAllowedMediaSchemes());
        
Home | Imprint | This part of the site doesn't use cookies.