mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
[2.1.3] Refine injector algorithm regarding behavior inside nodes that allow paragraphs inside them
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1423 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
094b20f58f
commit
c8b020879d
3
NEWS
3
NEWS
@ -19,6 +19,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
has 'id' attribute fixed, thanks NykO18 for reporting
|
has 'id' attribute fixed, thanks NykO18 for reporting
|
||||||
- Fix warning emitted when a non-supported URI scheme is passed to the
|
- Fix warning emitted when a non-supported URI scheme is passed to the
|
||||||
MakeAbsolute URIFilter, thanks NykO18 (again)
|
MakeAbsolute URIFilter, thanks NykO18 (again)
|
||||||
|
- Further refine AutoParagraph injector. Behavior inside of elements
|
||||||
|
allowing paragraph tags clarified: only inline content delimeted by
|
||||||
|
double newlines (not block elements) are paragraphed.
|
||||||
. %Core.AcceptFullDocuments renamed to %Core.ConvertDocumentToFragment
|
. %Core.AcceptFullDocuments renamed to %Core.ConvertDocumentToFragment
|
||||||
to better communicate its purpose
|
to better communicate its purpose
|
||||||
|
|
||||||
|
@ -6,20 +6,28 @@ HTMLPurifier_ConfigSchema::define(
|
|||||||
'AutoFormat', 'AutoParagraph', false, 'bool', '
|
'AutoFormat', 'AutoParagraph', false, 'bool', '
|
||||||
<p>
|
<p>
|
||||||
This directive turns on auto-paragraphing, where double newlines are
|
This directive turns on auto-paragraphing, where double newlines are
|
||||||
converted in to paragraphs whenever possible. Auto-paragraphing
|
converted in to paragraphs whenever possible. Auto-paragraphing:
|
||||||
applies when:
|
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>There are inline elements or text in the root node</li>
|
<li>Always applies to inline elements or text in the root node,</li>
|
||||||
<li>There are inline elements or text with double newlines or
|
<li>Applies to inline elements or text with double newlines in nodes
|
||||||
block elements in nodes that allow paragraph tags</li>
|
that allow paragraph tags,</li>
|
||||||
<li>There are double newlines in paragraph tags</li>
|
<li>Applies to double newlines in paragraph tags</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<code>p</code> tags must be allowed for this directive to take effect.
|
<code>p</code> tags must be allowed for this directive to take effect.
|
||||||
We do not use <code>br</code> tags for paragraphing, as that is
|
We do not use <code>br</code> tags for paragraphing, as that is
|
||||||
semantically incorrect.
|
semantically incorrect.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
To prevent auto-paragraphing as a content-producer, refrain from using
|
||||||
|
double-newlines except to specify a new paragraph or in contexts where
|
||||||
|
it has special meaning (whitespace usually has no meaning except in
|
||||||
|
tags like <code>pre</code>, so this should not be difficult.) To prevent
|
||||||
|
the paragraphing of inline text adjacent to block elements, wrap them
|
||||||
|
in <code>div</code> tags (the behavior is slightly different outside of
|
||||||
|
the root node.)
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
This directive has been available since 2.0.1.
|
This directive has been available since 2.0.1.
|
||||||
</p>
|
</p>
|
||||||
@ -62,19 +70,27 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
|
|||||||
$ok = false;
|
$ok = false;
|
||||||
// test if up-coming tokens are either block or have
|
// test if up-coming tokens are either block or have
|
||||||
// a double newline in them
|
// a double newline in them
|
||||||
|
$nesting = 0;
|
||||||
for ($i = $this->inputIndex + 1; isset($this->inputTokens[$i]); $i++) {
|
for ($i = $this->inputIndex + 1; isset($this->inputTokens[$i]); $i++) {
|
||||||
if ($this->inputTokens[$i]->type == 'start'){
|
if ($this->inputTokens[$i]->type == 'start'){
|
||||||
if (!$this->_isInline($this->inputTokens[$i])) {
|
if (!$this->_isInline($this->inputTokens[$i])) {
|
||||||
$ok = true;
|
// we haven't found a double-newline, and
|
||||||
|
// we've hit a block element, so don't paragraph
|
||||||
|
$ok = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
$nesting++;
|
||||||
|
}
|
||||||
|
if ($this->inputTokens[$i]->type == 'end') {
|
||||||
|
if ($nesting <= 0) break;
|
||||||
|
$nesting--;
|
||||||
}
|
}
|
||||||
if ($this->inputTokens[$i]->type == 'end') break;
|
|
||||||
if ($this->inputTokens[$i]->type == 'text') {
|
if ($this->inputTokens[$i]->type == 'text') {
|
||||||
|
// found it!
|
||||||
if (strpos($this->inputTokens[$i]->data, "\n\n") !== false) {
|
if (strpos($this->inputTokens[$i]->data, "\n\n") !== false) {
|
||||||
$ok = true;
|
$ok = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!$this->inputTokens[$i]->is_whitespace) break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($ok) {
|
if ($ok) {
|
||||||
|
@ -105,6 +105,8 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
// if all goes well, this token will be passed through unharmed
|
// if all goes well, this token will be passed through unharmed
|
||||||
$token = $tokens[$this->inputIndex];
|
$token = $tokens[$this->inputIndex];
|
||||||
|
|
||||||
|
//printTokens($tokens, $this->inputIndex);
|
||||||
|
|
||||||
foreach ($this->injectors as $i => $x) {
|
foreach ($this->injectors as $i => $x) {
|
||||||
if ($x->skip > 0) $this->injectors[$i]->skip--;
|
if ($x->skip > 0) $this->injectors[$i]->skip--;
|
||||||
}
|
}
|
||||||
|
@ -194,10 +194,7 @@ Bar</p></div>',
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testNoParagraphSingleInlineNodeInBlockNode() {
|
function testNoParagraphSingleInlineNodeInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult( '<div><b>Foo</b></div>' );
|
||||||
'<div><b>Foo</b></div>',
|
|
||||||
'<div><b>Foo</b></div>'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testParagraphInBlockquote() {
|
function testParagraphInBlockquote() {
|
||||||
@ -277,9 +274,7 @@ Par1
|
|||||||
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>Par1
|
'<div>Par1
|
||||||
<div>Par2</div></div>',
|
<div>Par2</div></div>'
|
||||||
'<div><p>Par1
|
|
||||||
</p><div>Par2</div></div>'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,6 +346,30 @@ Par2'
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testInlineAndBlockTagInDivNoParagraph() {
|
||||||
|
$this->assertResult(
|
||||||
|
'<div><code>bar</code> mmm <pre>asdf</pre></div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testInlineAndBlockTagInDivNeedingParagraph() {
|
||||||
|
$this->assertResult(
|
||||||
|
'<div><code>bar</code> mmm
|
||||||
|
|
||||||
|
<pre>asdf</pre></div>',
|
||||||
|
'<div><p><code>bar</code> mmm</p><pre>asdf</pre></div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph() {
|
||||||
|
$this->assertResult(
|
||||||
|
'<div>asdf <code>bar</code> mmm
|
||||||
|
|
||||||
|
<pre>asdf</pre></div>',
|
||||||
|
'<div><p>asdf <code>bar</code> mmm</p><pre>asdf</pre></div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function testErrorNeeded() {
|
function testErrorNeeded() {
|
||||||
$this->config->set('HTML', 'Allowed', 'b');
|
$this->config->set('HTML', 'Allowed', 'b');
|
||||||
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
||||||
|
Loading…
Reference in New Issue
Block a user