mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
[2.0.1] Implement error messages for MakeWellFormed. Armor AutoParagraph generated p start tags from these tag closing errors. Fix another auto-paragraphing edge-case. Create common Strategy error harness.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1242 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -230,6 +230,13 @@ Par1
|
||||
</p><div>Par2</div>'
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
<b>Par2</b>',
|
||||
'<p>Par1</p><p><b>Par2</b></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testInlineRootNode() {
|
||||
|
20
tests/HTMLPurifier/Strategy/ErrorsHarness.php
Normal file
20
tests/HTMLPurifier/Strategy/ErrorsHarness.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/ErrorsHarness.php';
|
||||
|
||||
class HTMLPurifier_Strategy_ErrorsHarness extends HTMLPurifier_ErrorsHarness
|
||||
{
|
||||
|
||||
// needs to be defined
|
||||
function getStrategy() {}
|
||||
|
||||
function invoke($input) {
|
||||
$strategy = $this->getStrategy();
|
||||
$lexer = new HTMLPurifier_Lexer_DirectLex();
|
||||
$tokens = $lexer->tokenizeHTML($input, $this->config, $this->context);
|
||||
$strategy->execute($tokens, $this->config, $this->context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
52
tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php
Normal file
52
tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/Strategy/ErrorsHarness.php';
|
||||
require_once 'HTMLPurifier/Strategy/MakeWellFormed.php';
|
||||
|
||||
/*
|
||||
'Strategy_MakeWellFormed: Tag closed by element end' => '',
|
||||
'Strategy_MakeWellFormed: Tag closed by document end' => '',
|
||||
*/
|
||||
|
||||
class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
|
||||
{
|
||||
|
||||
function getStrategy() {
|
||||
return new HTMLPurifier_Strategy_MakeWellFormed();
|
||||
}
|
||||
|
||||
function testUnnecessaryEndTagRemoved() {
|
||||
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed', 'b');
|
||||
$this->invoke('</b>');
|
||||
}
|
||||
|
||||
function testUnnecessaryEndTagToText() {
|
||||
$this->config->set('Core', 'EscapeInvalidTags', true);
|
||||
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text', 'b');
|
||||
$this->invoke('</b>');
|
||||
}
|
||||
|
||||
function testStrayEndTagRemoved() {
|
||||
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed', 'b');
|
||||
$this->invoke('<i></b></i>');
|
||||
}
|
||||
|
||||
function testStrayEndTagToText() {
|
||||
$this->config->set('Core', 'EscapeInvalidTags', true);
|
||||
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text', 'b');
|
||||
$this->invoke('<i></b></i>');
|
||||
}
|
||||
|
||||
function testTagClosedByElementEnd() {
|
||||
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', 'b');
|
||||
$this->invoke('<i><b>Foobar</i>');
|
||||
}
|
||||
|
||||
function testTagClosedByDocumentEnd() {
|
||||
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', 'b');
|
||||
$this->invoke('<b>Foobar');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/ErrorsHarness.php';
|
||||
require_once 'HTMLPurifier/Strategy/ErrorsHarness.php';
|
||||
require_once 'HTMLPurifier/Strategy/RemoveForeignElements.php';
|
||||
|
||||
class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
|
||||
{
|
||||
|
||||
function setup() {
|
||||
@@ -11,11 +11,8 @@ class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifie
|
||||
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
||||
}
|
||||
|
||||
function invoke($input) {
|
||||
$strategy = new HTMLPurifier_Strategy_RemoveForeignElements();
|
||||
$lexer = new HTMLPurifier_Lexer_DirectLex();
|
||||
$tokens = $lexer->tokenizeHTML($input, $this->config, $this->context);
|
||||
$strategy->execute($tokens, $this->config, $this->context);
|
||||
function getStrategy() {
|
||||
return new HTMLPurifier_Strategy_RemoveForeignElements();
|
||||
}
|
||||
|
||||
function testTagTransform() {
|
||||
@@ -31,12 +28,14 @@ class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifie
|
||||
}
|
||||
|
||||
function testForeignElementToText() {
|
||||
// uses $CurrentToken.Serialized
|
||||
$this->config->set('Core', 'EscapeInvalidTags', true);
|
||||
$this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text', 'cannot-possibly-exist-element');
|
||||
$this->invoke('<cannot-possibly-exist-element>');
|
||||
}
|
||||
|
||||
function testForeignElementRemoved() {
|
||||
// uses $CurrentToken.Serialized
|
||||
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed', 'cannot-possibly-exist-element');
|
||||
$this->invoke('<cannot-possibly-exist-element>');
|
||||
}
|
||||
|
@@ -94,6 +94,7 @@ $test_files[] = 'HTMLPurifier/Strategy/CompositeTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/CoreTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/FixNestingTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/MakeWellFormedTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/RemoveForeignElementsTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php';
|
||||
$test_files[] = 'HTMLPurifier/Strategy/ValidateAttributesTest.php';
|
||||
|
Reference in New Issue
Block a user