From 275932ec05b56db7bfd1d8a26e13ce7aa1e53030 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 26 Jun 2007 16:08:42 +0000 Subject: [PATCH] [2.0.1] Fix DirectLex's incomprehension of un-armored script contents as CDATA using custom preg_replace_callback git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1244 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/Lexer.php | 1 - library/HTMLPurifier/Lexer/DirectLex.php | 17 +++++++++++++++++ tests/HTMLPurifier/HTMLModule/ScriptingTest.php | 7 ------- tests/HTMLPurifier/LexerTest.php | 11 +++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php index c1b83d18..57950254 100644 --- a/library/HTMLPurifier/Lexer.php +++ b/library/HTMLPurifier/Lexer.php @@ -274,7 +274,6 @@ class HTMLPurifier_Lexer * Special CDATA case that is especiall convoluted for )#si', + array('HTMLPurifier_Lexer_DirectLex', 'scriptCallback'), $html); + } + $html = $this->normalize($html, $config, $context); $cursor = 0; // our location in the text diff --git a/tests/HTMLPurifier/HTMLModule/ScriptingTest.php b/tests/HTMLPurifier/HTMLModule/ScriptingTest.php index 1f06b2a5..ce108f7b 100644 --- a/tests/HTMLPurifier/HTMLModule/ScriptingTest.php +++ b/tests/HTMLPurifier/HTMLModule/ScriptingTest.php @@ -46,13 +46,6 @@ alert(""); array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false) ); - // invalid children - $this->assertResult( - '', - '', - array('HTML.Trusted' => true, 'Core.CommentScriptContents' => false) - ); - } } diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index d250493a..f80159be 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -315,6 +315,17 @@ class HTMLPurifier_LexerTest extends UnitTestCase $sax_expect[21] = false; $dom_expect[21] = false; + // test CDATA tags + $input[22] = ''; + $expect[22] = array( + new HTMLPurifier_Token_Start('script') + ,new HTMLPurifier_Token_Text('alert("");') + ,new HTMLPurifier_Token_End('script') + ); + $config[22] = HTMLPurifier_Config::create(array('HTML.Trusted' => true)); + $sax_expect[22] = false; + //$dom_expect[22] = false; + $default_config = HTMLPurifier_Config::createDefault(); $default_context = new HTMLPurifier_Context(); foreach($input as $i => $discard) {