From 694583259c3d2a6d1a30fc5e97556d8c31b95b1e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 15 Feb 2010 02:55:33 -0500 Subject: [PATCH] Fix autoparagraph bug with non-inline elements. Signed-off-by: Edward Z. Yang --- library/HTMLPurifier/Injector/AutoParagraph.php | 21 +++++++++++++-------- tests/HTMLPurifier/Injector/AutoParagraphTest.php | 7 +++++++ .../Strategy/MakeWellFormed_InjectorTest.php | 2 -- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/library/HTMLPurifier/Injector/AutoParagraph.php b/library/HTMLPurifier/Injector/AutoParagraph.php index 8cc95254..afa76089 100644 --- a/library/HTMLPurifier/Injector/AutoParagraph.php +++ b/library/HTMLPurifier/Injector/AutoParagraph.php @@ -34,16 +34,21 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector // ---- // This is a degenerate case } else { - // State 1.2: PAR1 - // ---- + if (!$token->is_whitespace || $this->_isInline($current)) { + // State 1.2: PAR1 + // ---- - // State 1.3: PAR1\n\nPAR2 - // ------------ + // State 1.3: PAR1\n\nPAR2 + // ------------ - // State 1.4:
PAR1\n\nPAR2 (see State 2) - // ------------ - $token = array($this->_pStart()); - $this->_splitText($text, $token); + // State 1.4:
PAR1\n\nPAR2 (see State 2) + // ------------ + $token = array($this->_pStart()); + $this->_splitText($text, $token); + } else { + // State 1.5: \n
+ // -- + } } } else { // State 2:
PAR1... (similar to 1.4) diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php index 22083cbf..e6abbd1f 100644 --- a/tests/HTMLPurifier/Injector/AutoParagraphTest.php +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -497,6 +497,13 @@ Bar
", ); } + function testAutoClose() { + $this->assertResult( + '

+
' + ); + } + function testErrorNeeded() { $this->config->set('HTML.Allowed', 'b'); $this->expectError('Cannot enable AutoParagraph injector because p is not allowed'); diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php index 123cff35..f0e01340 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php @@ -123,8 +123,6 @@ asdf

asdf

- - " ); } -- 2.11.4.GIT