8000 [HtmlSanitizer] Ignore Processing Instructions by smnandre · Pull Request #54513 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HtmlSanitizer] Ignore Processing Instructions #54513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HtmlSanitizer] Ignore Processing Instructions
  • Loading branch information
smnandre committed Apr 6, 2024
commit 3582bdd13c96883d567426c94975cb5419ba863c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ public static function provideSanitizeBody()
'Lorem ipsum ',
],

// Processing instructions
[
'Lorem ipsum<?div x?>foo',
'Lorem ipsumfoo',
],

// Normal tags
[
'<abbr>Lorem ipsum</abbr>',
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/HtmlSanitizer/Visitor/DomVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ private function visitChildren(\DOMNode $domNode, Cursor $cursor): void
if ('#text' === $child->nodeName) {
// Add text directly for performance
$cursor->node->addChild(new TextNode($cursor->node, $child->nodeValue));
} elseif (!$child instanceof \DOMText) {
} elseif (!$child instanceof \DOMText && !$child instanceof \DOMProcessingInstruction) {
// Otherwise continue the visit recursively
// Ignore comments for security reasons (interpreted differently by browsers)
// Ignore processing instructions (treated as comments)
$this->visitNode($child, $cursor);
}
}
Expand Down
0