Skip to content

Commit

Permalink
Make IE conditional comment matching ungreedy.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Sep 28, 2010
1 parent 882ffed commit d848c99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
. Internal change
==========================

4.2.1, unknown release date
- Make removal of conditional IE comments ungreedy; thanks Bernd
for reporting.

4.2.0, released 2010-09-15
! Added %Core.RemoveProcessingInstructions, which lets you remove
<? ... ?> statements.
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected static function escapeCommentedCDATA($string) {
*/
protected static function removeIEConditional($string) {
return preg_replace(
'#<!--\[if [^>]+\]>.*<!\[endif\]-->#si', // probably should generalize for all strings
'#<!--\[if [^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings
'',
$string
);
Expand Down
26 changes: 19 additions & 7 deletions tests/HTMLPurifier/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,21 +727,33 @@ function test_tokenizeHTML_removeProcessingInstruction() {

function test_tokenizeHTML_removeNewline() {
$this->config->set('Core.NormalizeNewlines', true);
$input = "plain\rtext\r\n";
$expect = array(
new HTMLPurifier_Token_Text("plain\ntext\n")
$this->assertTokenization(
"plain\rtext\r\n",
array(
new HTMLPurifier_Token_Text("plain\ntext\n")
)
);
}

function test_tokenizeHTML_noRemoveNewline() {
$this->config->set('Core.NormalizeNewlines', false);
$input = "plain\rtext\r\n";
$expect = array(
new HTMLPurifier_Token_Text("plain\rtext\r\n")
$this->assertTokenization(
"plain\rtext\r\n",
array(
new HTMLPurifier_Token_Text("plain\rtext\r\n")
)
);
$this->assertTokenization($input, $expect);
}

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")
)
);
}


/*
Expand Down

0 comments on commit d848c99

Please sign in to comment.