htmlLower example

public function visit(\DOMDocumentFragment $domNode): ?NodeInterface
    {
        $cursor = new Cursor(new DocumentNode());
        $this->visitChildren($domNode$cursor);

        return $cursor->node;
    }

    private function visitNode(\DOMNode $domNode, Cursor $cursor): void
    {
        $nodeName = StringSanitizer::htmlLower($domNode->nodeName);

        // Element should be dropped, including its children         if (!\array_key_exists($nodeName$this->elementsConfig)) {
            return;
        }

        // Otherwise, visit recursively         $this->enterNode($nodeName$domNode$cursor);
        $this->visitChildren($domNode$cursor);
        $cursor->node = $cursor->node->getParent();
    }

    
$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,
            $input
        );
    }

    private function sanitizeWithContext(string $context, string $input): string
    {
        // Text context: early return with HTML encoding         if (W3CReference::CONTEXT_TEXT === $context) {
            return StringSanitizer::encodeHtmlEntities($input);
        }

        
foreach ($cases as $input => $expected) {
            yield $input => [$input$expected];
        }
    }

    /** * @dataProvider provideHtmlLower */
    public function testHtmlLower(string $input, string $expected)
    {
        $this->assertSame($expected, StringSanitizer::htmlLower($input));
    }

    public static function provideEncodeHtmlEntites()
    {
        $cases = [
            '' => '',
            '"' => '"',
            '\'' => ''',
            '&' => '&',
            '<' => '&lt;',
            '>' => '&gt;',
            
Home | Imprint | This part of the site doesn't use cookies.