diff --git a/NEWS b/NEWS index 94605b0c..c78f781f 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier + PHP4 reference/foreach cruft removed (in progress) ! CSS properties are no case-insensitive ! DefinitionCacheFactory now can register new implementations +! #isU', array($this, 'styleCallback'), $html); + $style_blocks = $this->_styleMatches; + $this->_styleMatches = array(); // reset + // this is a persistent context, so we have to overwrite it with every call + if ($context->exists('StyleBlocks')) $context->destroy('StyleBlocks'); + $context->register('StyleBlocks', $style_blocks); return $html; } diff --git a/library/HTMLPurifier/Lexer/DOMLex.php b/library/HTMLPurifier/Lexer/DOMLex.php index 1726a55c..6f6f0183 100644 --- a/library/HTMLPurifier/Lexer/DOMLex.php +++ b/library/HTMLPurifier/Lexer/DOMLex.php @@ -186,6 +186,7 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer $ret .= ''; $ret .= ''; + // No protection if $html contains a stray ! $ret .= '
'.$html.'
'; return $ret; } diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index ec24b431..df89d137 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -31,6 +31,48 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness $this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex'); } + // HTMLPurifier_Lexer->extractStyleBlocks() -------------------------------- + + function assertExtractStyleBlocks($html, $expect = true, $styles = array()) { + $lexer = HTMLPurifier_Lexer::create($this->config); + if ($expect === true) $expect = $html; + $result = $lexer->extractStyleBlocks($html, $this->config, $this->context); + $this->assertIdentical($result, $expect); + $this->assertIdentical($this->context->get('StyleBlocks'), $styles); + } + + function test_extractStyleBlocks_preserve() { + $this->assertExtractStyleBlocks('Foobar'); + } + + function test_extractStyleBlocks_allStyle() { + $this->assertExtractStyleBlocks('', '', array('foo')); + } + + function test_extractStyleBlocks_multipleBlocks() { + $this->assertExtractStyleBlocks( + "NOP", + "NOP", + array('1', '2', '4') + ); + } + + function test_extractStyleBlocks_blockWithAttributes() { + $this->assertExtractStyleBlocks( + '', + '', + array('css') + ); + } + + function test_extractStyleBlocks_styleWithPadding() { + $this->assertExtractStyleBlocks( + "AlasAwesome\n Trendy!", + "AlasAwesome\n Trendy!", + array('foo') + ); + } + // HTMLPurifier_Lexer->parseData() ----------------------------------------- function assertParseData($input, $expect = true) { @@ -511,6 +553,17 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness ); } + function test_tokenizeHTML_extractStyleBlocks() { + $this->config->set('HTML', 'ExtractStyleBlocks', true); + $this->assertTokenization( + 'Test', + array( + new HTMLPurifier_Token_Text('Test') + ) + ); + $this->assertIdentical($this->context->get('StyleBlocks'), array('.foo {text-align:center;}')); + } + /* function test_tokenizeHTML_() {