8000 bug #54513 [HtmlSanitizer] Ignore Processing Instructions (smnandre) · symfony/symfony@00ba3ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 00ba3ad

Browse files
committed
bug #54513 [HtmlSanitizer] Ignore Processing Instructions (smnandre)
This PR was merged into the 6.4 branch. Discussion ---------- [HtmlSanitizer] Ignore Processing Instructions | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54492 | License | MIT Ignore Processing Instructions (as comments) to avoid mixing them with standard DOM nodes (see #54492) (targetting 6.4 as the component was released in 6.1)) Commits ------- 3582bdd [HtmlSanitizer] Ignore Processing Instructions
2 parents b293ffe + 3582bdd commit 00ba3ad

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ public static function provideSanitizeBody()
309309
'Lorem ipsum ',
310310
],
311311

312+
// Processing instructions
313+
[
314+
'Lorem ipsum<?div x?>foo',
315+
'Lorem ipsumfoo',
316+
],
317+
312318
// Normal tags
313319
[
314320
'<abbr>Lorem ipsum</abbr>',

src/Symfony/Component/HtmlSanitizer/Visitor/DomVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ private function visitChildren(\DOMNode $domNode, Cursor $cursor): void
134134
if ('#text' === $child->nodeName) {
135135
// Add text directly for performance
136136
$cursor->node->addChild(new TextNode($cursor->node, $child->nodeValue));
137-
} elseif (!$child instanceof \DOMText) {
137+
} elseif (!$child instanceof \DOMText && !$child instanceof \DOMProcessingInstruction) {
138138
// Otherwise continue the visit recursively
139139
// Ignore comments for security reasons (interpreted differently by browsers)
140+
// Ignore processing instructions (treated as comments)
140141
$this->visitNode($child, $cursor);
141142
}
142143
}

0 commit comments

Comments
 (0)
0