MastermindsParser example

private HtmlSanitizerConfig $config;
    private ParserInterface $parser;

    /** * @var array<string, DomVisitor> */
    private array $domVisitors = [];

    public function __construct(HtmlSanitizerConfig $config, ParserInterface $parser = null)
    {
        $this->config = $config;
        $this->parser = $parser ?? new MastermindsParser();
    }

    public function sanitize(string $input): string
    {
        return $this->sanitizeWithContext(W3CReference::CONTEXT_BODY, $input);
    }

    public function sanitizeFor(string $element, string $input): string
    {
        return $this->sanitizeWithContext(
            W3CReference::CONTEXTS_MAP[StringSanitizer::htmlLower($element)] ?? W3CReference::CONTEXT_BODY,
            


namespace Symfony\Component\HtmlSanitizer\Tests\Parser;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HtmlSanitizer\Parser\MastermindsParser;

class MastermindsParserTest extends TestCase
{
    public function testParseValid()
    {
        $node = (new MastermindsParser())->parse('<div></div>');
        $this->assertInstanceOf(\DOMNode::class$node);
        $this->assertSame('#document-fragment', $node->nodeName);
        $this->assertCount(1, $node->childNodes);
        $this->assertSame('div', $node->childNodes->item(0)->nodeName);
    }
}
Home | Imprint | This part of the site doesn't use cookies.