Skip to content

Commit

Permalink
ignore conditional comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fkoyer committed Mar 12, 2024
1 parent 9ca5a36 commit b7bf895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
16 changes: 0 additions & 16 deletions library/HTMLPurifier/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,6 @@ protected static function escapeCommentedCDATA($string)
);
}

/**
* Special Internet Explorer conditional comments should be removed.
* @param string $string HTML string to process.
* @return string HTML with conditional comments removed.
*/
protected static function removeIEConditional($string)
{
return preg_replace(
'#<!--\[if [^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings
'',
$string
);
}

/**
* Callback function for escapeCDATA() that does the work.
*
Expand Down Expand Up @@ -323,8 +309,6 @@ public function normalize($html, $config, $context)
// escape CDATA
$html = $this->escapeCDATA($html);

$html = $this->removeIEConditional($html);

// extract body from document if applicable
if ($config->get('Core.ConvertDocumentToFragment')) {
$e = false;
Expand Down
32 changes: 14 additions & 18 deletions tests/HTMLPurifier/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ public function test_tokenizeHTML_malformedComment()
);
}

public function test_tokenizeHTML_conditionalComments()
{
$this->assertTokenization(
'<!--[if mso]>A<![endif]-->B<!--[if !mso]><!---->C<!-- <![endif]-->',
array(
new HTMLPurifier_Token_Comment('[if mso]>A<![endif]'),
new HTMLPurifier_Token_Text("B"),
new HTMLPurifier_Token_Comment('[if !mso]><!--'),
new HTMLPurifier_Token_Text("C"),
new HTMLPurifier_Token_Comment(' <![endif]'),
)
);
}

public function test_tokenizeHTML_unterminatedTag()
{
$this->assertTokenization(
Expand Down Expand Up @@ -785,14 +799,6 @@ public function test_tokenizeHTML_()
);
}

public function test_tokenizeHTML_ignoreIECondComment()
{
$this->assertTokenization(
'<!--[if IE]>foo<a>bar<!-- baz --><![endif]-->',
array()
);
}

public function test_tokenizeHTML_removeProcessingInstruction()
{
$this->config->set('Core.RemoveProcessingInstructions', true);
Expand Down Expand Up @@ -824,16 +830,6 @@ public function test_tokenizeHTML_noRemoveNewline()
);
}

public function test_tokenizeHTML_conditionalCommentUngreedy()
{
$this->assertTokenization(
'<!--[if gte mso 9]>a<![endif]-->b<!--[if gte mso 9]>c<![endif]-->',
array(
new HTMLPurifier_Token_Text("b")
)
);
}

public function test_tokenizeHTML_imgTag()
{
$start = array(
Expand Down

0 comments on commit b7bf895

Please sign in to comment.