8000 fix: Ignore conditional comments by fkoyer · Pull Request #401 · ezyang/htmlpurifier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Ignore conditional comments #401

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 1 commit into from
Mar 13, 2024
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
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
36 changes: 18 additions & 18 deletions tests/HTMLPurifier/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,24 @@ public function test_tokenizeHTML_malformedComment()
);
}

/**
* Conditional comments are not supported by HTMLPurifier, but we
* should make sure they don't break the lexer.
*/
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 +803,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 +834,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