From 28c29656af08a9d1b8a48c80004be55fa09b0806 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 9 Sep 2007 01:27:09 +0000 Subject: [PATCH] [2.1.3] Fix off-by-one bug in injector functionality for dormant injectors git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1415 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 2 ++ library/HTMLPurifier/Injector.php | 3 +++ library/HTMLPurifier/Strategy/MakeWellFormed.php | 8 +++++++- .../HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 98f7a642..0027c556 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier 2.1.3, unknown release date - Fixed poor include ordering for Email URI AttrDefs, causes fatal errors on some systems. +- Injector algorithm further refined: off-by-one error regarding skip + counts for dormant injectors fixed 2.1.2, released 2007-09-03 ! Implemented Object module for trusted users diff --git a/library/HTMLPurifier/Injector.php b/library/HTMLPurifier/Injector.php index 59017163..261a2a80 100644 --- a/library/HTMLPurifier/Injector.php +++ b/library/HTMLPurifier/Injector.php @@ -4,6 +4,9 @@ * Injects tokens into the document while parsing for well-formedness. * This enables "formatter-like" functionality such as auto-paragraphing, * smiley-ification and linkification to take place. + * + * @todo Allow injectors to request a re-run on their output. This + * would help if an operation is recursive. */ class HTMLPurifier_Injector { diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index b3e8aa74..b8173f6d 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -286,8 +286,14 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy // adjust the injector skips based on the array substitution if ($this->injectors) { - $offset = count($token) + 1; + $offset = count($token); for ($i = 0; $i <= $this->currentInjector; $i++) { + // because of the skip back, we need to add one more + // for uninitialized injectors. I'm not exactly + // sure why this is the case, but I think it has to + // do with the fact that we're decrementing skips + // before re-checking text + if (!$this->injectors[$i]->skip) $this->injectors[$i]->skip++; $this->injectors[$i]->skip += $offset; } } diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php index e8e6c797..04756201 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php @@ -62,4 +62,11 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str ); } + function testParagraphAfterLinkifiedURL() { + $this->assertResult( + "http://google.com\n\nb", + "

http://google.com

b

" + ); + } + }