0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

[2.1.0] Implement Ruby.

- Destroy some zombie context variables
- Reorganize some TODO items

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1347 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-08-02 22:44:42 +00:00
parent 7bccc24977
commit f5b72c623c
11 changed files with 107 additions and 18 deletions

13
TODO
View File

@ -7,13 +7,12 @@ TODO List
? Maybe I'll Do It ? Maybe I'll Do It
========================== ==========================
If no interest is expressed for a feature that may required a considerable
amount of effort to implement, it may get endlessly delayed. Do not be
afraid to cast your vote for the next feature to be implemented!
2.1 release [Refactor, refactor!] 2.1 release [Refactor, refactor!]
# URI validation routines tighter (see docs/dev-code-quality.html) (COMPLEX)
# Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
# Ruby support
- Configuration profiles: predefined directives set with one func call - Configuration profiles: predefined directives set with one func call
- Implement IDREF support (harder than it seems, since you cannot have
IDREFs to non-existent IDs)
- Allow non-ASCII characters in font names - Allow non-ASCII characters in font names
- Explain how to use HTML Purifier in non-PHP languages / create - Explain how to use HTML Purifier in non-PHP languages / create
a simple command line stub a simple command line stub
@ -39,6 +38,8 @@ TODO List
2.4 release [It's All About Trust] (floating) 2.4 release [It's All About Trust] (floating)
# Implement untrusted, dangerous elements/attributes # Implement untrusted, dangerous elements/attributes
# Implement IDREF support (harder than it seems, since you cannot have
IDREFs to non-existent IDs)
3.0 release [Beyond HTML] 3.0 release [Beyond HTML]
# Legit token based CSS parsing (will require revamping almost every # Legit token based CSS parsing (will require revamping almost every
@ -77,6 +78,8 @@ Unknown release (on a scratch-an-itch basis)
- Reorganize Unit Tests - Reorganize Unit Tests
- Refactor loop tests: Lexer - Refactor loop tests: Lexer
- Reorganize configuration directives (Create more namespaces! Get messy!) - Reorganize configuration directives (Create more namespaces! Get messy!)
- Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
- Implement lenient <ruby> child validation
Requested Requested

View File

@ -11,8 +11,7 @@ docs/examples/demo.php - ad hoc HTML/PHP soup to the extreme
AttrDef - a lot of duplication, more generic classes need to be created; AttrDef - a lot of duplication, more generic classes need to be created;
a lot of strtolower() calls, no legit casing a lot of strtolower() calls, no legit casing
Class - doesn't support Unicode characters (fringe); uses regular Class - doesn't support Unicode characters (fringe); uses regular expressions
expressions
Lang - code duplication; premature optimization Lang - code duplication; premature optimization
Length - easily mistaken for CSSLength Length - easily mistaken for CSSLength
URI - multiple regular expressions; missing validation for parts (?) URI - multiple regular expressions; missing validation for parts (?)
@ -22,9 +21,6 @@ ConfigSchema - redefinition is a mess
Strategy Strategy
FixNesting - cannot bubble nodes out of structures, duplicated checks FixNesting - cannot bubble nodes out of structures, duplicated checks
for special-case parent node for special-case parent node
MakeWellFormed - insufficient automatic closing definitions (check HTML
spec for optional end tags, also, closing based on type (block/inline)
might be efficient).
RemoveForeignElements - should be run in parallel with MakeWellFormed RemoveForeignElements - should be run in parallel with MakeWellFormed
URIScheme - needs to have callable generic checks URIScheme - needs to have callable generic checks
mailto - doesn't validate emails, doesn't validate querystring mailto - doesn't validate emails, doesn't validate querystring

View File

@ -2,7 +2,8 @@
Configuration Ideas Configuration Ideas
Here are some theoretical configuration ideas that we could implement some Here are some theoretical configuration ideas that we could implement some
time. Note the naming convention: %Namespace.Directive time. Note the naming convention: %Namespace.Directive. If you want one
implemented, give us a ring, and we'll move it up the priority chain.
%Attr.RewriteFragments - if there's %Attr.IDPrefix we may want to transparently %Attr.RewriteFragments - if there's %Attr.IDPrefix we may want to transparently
rewrite the URLs we parse too. However, we can only do it when it's a pure rewrite the URLs we parse too. However, we can only do it when it's a pure

View File

@ -0,0 +1,28 @@
<?php
require_once 'HTMLPurifier/HTMLModule.php';
/**
* XHTML 1.1 Ruby Annotation Module, defines elements that indicate
* short runs of text alongside base text for annotation or pronounciation.
*/
class HTMLPurifier_HTMLModule_Ruby extends HTMLPurifier_HTMLModule
{
var $name = 'Ruby';
function HTMLPurifier_HTMLModule_Ruby() {
$this->addElement('ruby', true, 'Inline',
'Custom: ((rb, (rt | (rp, rt, rp))) | (rbc, rtc, rtc?))',
'Common');
$this->addElement('rbc', true, false, 'Required: rb', 'Common');
$this->addElement('rtc', true, false, 'Required: rt', 'Common');
$rb =& $this->addElement('rb', true, false, 'Inline', 'Common');
$rb->excludes = array('ruby' => true);
$rt =& $this->addElement('rt', true, false, 'Inline', 'Common', array('rbspan' => 'Number'));
$rt->excludes = array('ruby' => true);
$this->addElement('rp', true, false, 'Optional: #PCDATA', 'Common');
}
}

View File

@ -28,6 +28,7 @@ require_once 'HTMLPurifier/HTMLModule/Target.php';
require_once 'HTMLPurifier/HTMLModule/Scripting.php'; require_once 'HTMLPurifier/HTMLModule/Scripting.php';
require_once 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php'; require_once 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php';
require_once 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php'; require_once 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php';
require_once 'HTMLPurifier/HTMLModule/Ruby.php';
// tidy modules // tidy modules
require_once 'HTMLPurifier/HTMLModule/Tidy.php'; require_once 'HTMLPurifier/HTMLModule/Tidy.php';
@ -215,7 +216,7 @@ class HTMLPurifier_HTMLModuleManager
$this->doctypes->register( $this->doctypes->register(
'XHTML 1.1', true, 'XHTML 1.1', true,
array_merge($common, $xml), array_merge($common, $xml, array('Ruby')),
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_XHTMLStrict'), // Tidy_XHTML1_1 array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_XHTMLStrict'), // Tidy_XHTML1_1
array(), array(),
'-//W3C//DTD XHTML 1.1//EN', '-//W3C//DTD XHTML 1.1//EN',

View File

@ -46,6 +46,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
} }
$context->destroy('IDAccumulator'); $context->destroy('IDAccumulator');
$context->destroy('CurrentToken');
return $tokens; return $tokens;
} }

View File

@ -74,6 +74,7 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
// setup config // setup config
if ($this->config) { if ($this->config) {
$config = HTMLPurifier_Config::create($this->config); $config = HTMLPurifier_Config::create($this->config);
$config->autoFinalize = false;
$config->loadArray($config_array); $config->loadArray($config_array);
} else { } else {
$config = HTMLPurifier_Config::create($config_array); $config = HTMLPurifier_Config::create($config_array);

View File

@ -0,0 +1,56 @@
<?php
require_once 'HTMLPurifier/HTMLModuleHarness.php';
class HTMLPurifier_HTMLModule_RubyTest extends HTMLPurifier_HTMLModuleHarness
{
function setUp() {
parent::setUp();
$this->config->set('HTML', 'Doctype', 'XHTML 1.1');
}
function testBasicUse() {
$this->assertResult(
'<ruby><rb>WWW</rb><rt>World Wide Web</rt></ruby>'
);
}
function testRPUse() {
$this->assertResult(
'<ruby><rb>WWW</rb><rp>(</rp><rt>World Wide Web</rt><rp>)</rp></ruby>'
);
}
function testComplexUse() {
$this->assertResult(
'<ruby>
<rbc>
<rb>10</rb>
<rb>31</rb>
<rb>2002</rb>
</rbc>
<rtc>
<rt>Month</rt>
<rt>Day</rt>
<rt>Year</rt>
</rtc>
<rtc>
<rt rbspan="3">Expiration Date</rt>
</rtc>
</ruby>'
);
/* not implemented
function testBackwardsCompat() {
$this->assertResult(
'<ruby>A<rp>(</rp><rt>aaa</rt><rp>)</rp></ruby>',
'<ruby><rb>A</rb><rp>(</rp><rt>aaa</rt><rp>)</rp></ruby>'
);
}
*/
}
}

View File

@ -63,12 +63,6 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<span><ins>Not allowed!</ins></span>' '<span><ins>Not allowed!</ins></span>'
); );
$this->assertResult( // alt config
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>',
array('Core.EscapeInvalidChildren' => true)
);
// test block element that has inline content // test block element that has inline content
$this->assertResult( $this->assertResult(
'<h1><ins><div>Not allowed!</div></ins></h1>', '<h1><ins><div>Not allowed!</div></ins></h1>',
@ -84,6 +78,12 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<div><ins><del><div>Allowed!</div></del></ins></div>' '<div><ins><del><div>Allowed!</div></del></ins></div>'
); );
$this->assertResult( // alt config
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>',
array('Core.EscapeInvalidChildren' => true)
);
} }
function testExclusionsIntegration() { function testExclusionsIntegration() {

View File

@ -6,6 +6,7 @@ class HTMLPurifier_StrategyHarness extends HTMLPurifier_ComplexHarness
{ {
function setUp() { function setUp() {
parent::setUp();
$this->func = 'execute'; $this->func = 'execute';
$this->to_tokens = true; $this->to_tokens = true;
$this->to_html = true; $this->to_html = true;

View File

@ -79,6 +79,7 @@ $test_files[] = 'HTMLPurifier/GeneratorTest.php';
$test_files[] = 'HTMLPurifier/HTMLDefinitionTest.php'; $test_files[] = 'HTMLPurifier/HTMLDefinitionTest.php';
$test_files[] = 'HTMLPurifier/HTMLModuleManagerTest.php'; $test_files[] = 'HTMLPurifier/HTMLModuleManagerTest.php';
$test_files[] = 'HTMLPurifier/HTMLModuleTest.php'; $test_files[] = 'HTMLPurifier/HTMLModuleTest.php';
$test_files[] = 'HTMLPurifier/HTMLModule/RubyTest.php';
$test_files[] = 'HTMLPurifier/HTMLModule/ScriptingTest.php'; $test_files[] = 'HTMLPurifier/HTMLModule/ScriptingTest.php';
$test_files[] = 'HTMLPurifier/HTMLModule/TidyTest.php'; $test_files[] = 'HTMLPurifier/HTMLModule/TidyTest.php';
$test_files[] = 'HTMLPurifier/IDAccumulatorTest.php'; $test_files[] = 'HTMLPurifier/IDAccumulatorTest.php';