From 733868a76d9a4854931bc2829ba0f1eec3987249 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 29 Jun 2007 17:48:56 +0000 Subject: [PATCH] [2.1.0] Fix another AutoParagraph edge-case. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1295 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/Injector/AutoParagraph.php | 9 ++++++++- tests/HTMLPurifier/Injector/AutoParagraphTest.php | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/HTMLPurifier/Injector/AutoParagraph.php b/library/HTMLPurifier/Injector/AutoParagraph.php index 24ca9d5e..6e0a6a3e 100644 --- a/library/HTMLPurifier/Injector/AutoParagraph.php +++ b/library/HTMLPurifier/Injector/AutoParagraph.php @@ -166,7 +166,14 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector $needs_start = false; $needs_end = false; - for ($i = 0, $c = count($raw_paragraphs); $i < $c; $i++) { + $c = count($raw_paragraphs); + if ($c == 1) { + // there were no double-newlines, abort quickly + $result[] = new HTMLPurifier_Token_Text($data); + return; + } + + for ($i = 0; $i < $c; $i++) { $par = $raw_paragraphs[$i]; if (trim($par) !== '') { $paragraphs[] = $par; diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php index 441be0de..0f0b5e5e 100644 --- a/tests/HTMLPurifier/Injector/AutoParagraphTest.php +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -261,6 +261,11 @@ Par1 '
asdf

asdf

' ); + $this->assertResult( +'One Two', +'

One Two

' + ); + } function testInlineRootNode() {