mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
[1.4.0] Support for configuration directive aliases added.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@668 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
2e16c4a968
commit
5e366b25f8
4
NEWS
4
NEWS
@ -17,7 +17,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! Configuration documentation looks nicer
|
! Configuration documentation looks nicer
|
||||||
! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode
|
! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode
|
||||||
characters while %Core.Encoding is set to a non-UTF-8 encoding.
|
characters while %Core.Encoding is set to a non-UTF-8 encoding.
|
||||||
- Replaced version check with functionality check for DOM
|
! Support for configuration directive aliases added
|
||||||
|
- Replaced version check with functionality check for DOM (thanks Stephen
|
||||||
|
Khoo)
|
||||||
. Added smoketest 'all.php', which loads all other smoketests via frames
|
. Added smoketest 'all.php', which loads all other smoketests via frames
|
||||||
. Implemented AttrDef_CSSURI for url(http://google.com) style declarations
|
. Implemented AttrDef_CSSURI for url(http://google.com) style declarations
|
||||||
. Added convenient single test selector form on test runner
|
. Added convenient single test selector form on test runner
|
||||||
|
4
TODO
4
TODO
@ -9,13 +9,13 @@ TODO List
|
|||||||
|
|
||||||
1.4 release
|
1.4 release
|
||||||
# Add hooks for custom behavior (for instance, YouTube preservation)
|
# Add hooks for custom behavior (for instance, YouTube preservation)
|
||||||
# Implement all non-essential attribute transforms
|
|
||||||
- Aggressive caching
|
- Aggressive caching
|
||||||
|
- Upgrade SimpleTest testing code to newest version
|
||||||
? Rich set* methods and config file loaders for HTMLPurifier_Config
|
? Rich set* methods and config file loaders for HTMLPurifier_Config
|
||||||
? Configuration profiles: sets of directives that get set with one func call
|
? Configuration profiles: sets of directives that get set with one func call
|
||||||
? ConfigSchema directive aliases (so we can rename some of them)
|
|
||||||
|
|
||||||
1.5 release
|
1.5 release
|
||||||
|
# Implement all non-essential attribute transforms
|
||||||
# URI validation routines tighter (see docs/dev-code-quality.html) (COMPLEX)
|
# URI validation routines tighter (see docs/dev-code-quality.html) (COMPLEX)
|
||||||
# Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
|
# Advanced URI filtering schemes (see docs/proposal-new-directives.txt)
|
||||||
# Error logging for filtering/cleanup procedures
|
# Error logging for filtering/cleanup procedures
|
||||||
|
@ -99,6 +99,8 @@ foreach($schema->info as $namespace_name => $namespace_info) {
|
|||||||
|
|
||||||
foreach ($namespace_info as $name => $info) {
|
foreach ($namespace_info as $name => $info) {
|
||||||
|
|
||||||
|
if ($info->class == 'alias') continue;
|
||||||
|
|
||||||
$dom_directive = $dom_document->createElement('directive');
|
$dom_directive = $dom_document->createElement('directive');
|
||||||
$dom_namespace->appendChild($dom_directive);
|
$dom_namespace->appendChild($dom_directive);
|
||||||
|
|
||||||
|
@ -75,12 +75,17 @@ class HTMLPurifier_Config
|
|||||||
* @param $namespace String namespace
|
* @param $namespace String namespace
|
||||||
* @param $key String key
|
* @param $key String key
|
||||||
*/
|
*/
|
||||||
function get($namespace, $key) {
|
function get($namespace, $key, $from_alias = false) {
|
||||||
if (!isset($this->def->info[$namespace][$key])) {
|
if (!isset($this->def->info[$namespace][$key])) {
|
||||||
trigger_error('Cannot retrieve value of undefined directive',
|
trigger_error('Cannot retrieve value of undefined directive',
|
||||||
E_USER_WARNING);
|
E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($this->def->info[$namespace][$key]->class == 'alias') {
|
||||||
|
trigger_error('Cannot get value from aliased directive, use real name',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
return $this->conf[$namespace][$key];
|
return $this->conf[$namespace][$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,12 +108,22 @@ class HTMLPurifier_Config
|
|||||||
* @param $key String key
|
* @param $key String key
|
||||||
* @param $value Mixed value
|
* @param $value Mixed value
|
||||||
*/
|
*/
|
||||||
function set($namespace, $key, $value) {
|
function set($namespace, $key, $value, $from_alias = false) {
|
||||||
if (!isset($this->def->info[$namespace][$key])) {
|
if (!isset($this->def->info[$namespace][$key])) {
|
||||||
trigger_error('Cannot set undefined directive to value',
|
trigger_error('Cannot set undefined directive to value',
|
||||||
E_USER_WARNING);
|
E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($this->def->info[$namespace][$key]->class == 'alias') {
|
||||||
|
if ($from_alias) {
|
||||||
|
trigger_error('Double-aliases not allowed, please fix '.
|
||||||
|
'ConfigSchema bug');
|
||||||
|
}
|
||||||
|
$this->set($this->def->info[$namespace][$key]->namespace,
|
||||||
|
$this->def->info[$namespace][$key]->name,
|
||||||
|
$value, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
$value = $this->def->validate(
|
$value = $this->def->validate(
|
||||||
$value,
|
$value,
|
||||||
$this->def->info[$namespace][$key]->type,
|
$this->def->info[$namespace][$key]->type,
|
||||||
|
@ -224,6 +224,46 @@ class HTMLPurifier_ConfigSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a directive alias for backwards compatibility
|
||||||
|
* @static
|
||||||
|
* @param $namespace
|
||||||
|
* @param $name Directive that will be aliased
|
||||||
|
* @param $new_namespace
|
||||||
|
* @param $new_name Directive that the alias will be to
|
||||||
|
*/
|
||||||
|
function defineAlias($namespace, $name, $new_namespace, $new_name) {
|
||||||
|
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||||
|
if (!isset($def->info[$namespace])) {
|
||||||
|
trigger_error('Cannot define directive alias for undefined namespace',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ctype_alnum($name)) {
|
||||||
|
trigger_error('Directive name must be alphanumeric',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isset($def->info[$namespace][$name])) {
|
||||||
|
trigger_error('Cannot define alias over directive',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isset($def->info[$new_namespace][$new_name])) {
|
||||||
|
trigger_error('Cannot define alias to undefined directive',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($def->info[$new_namespace][$new_name]->class == 'alias') {
|
||||||
|
trigger_error('Cannot define alias to alias',
|
||||||
|
E_USER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$def->info[$namespace][$name] = new HTMLPurifier_ConfigEntity_DirectiveAlias();
|
||||||
|
$def->info[$namespace][$name]->namespace = $new_namespace;
|
||||||
|
$def->info[$namespace][$name]->name = $new_name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a variable according to type. Return null if invalid.
|
* Validate a variable according to type. Return null if invalid.
|
||||||
*/
|
*/
|
||||||
@ -318,13 +358,17 @@ class HTMLPurifier_ConfigSchema {
|
|||||||
/**
|
/**
|
||||||
* Base class for configuration entity
|
* Base class for configuration entity
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_ConfigEntity {}
|
class HTMLPurifier_ConfigEntity {
|
||||||
|
var $class = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure object describing of a namespace
|
* Structure object describing of a namespace
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_ConfigEntity_Namespace extends HTMLPurifier_ConfigEntity {
|
class HTMLPurifier_ConfigEntity_Namespace extends HTMLPurifier_ConfigEntity {
|
||||||
|
|
||||||
|
var $class = 'namespace';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String description of what kinds of directives go in this namespace.
|
* String description of what kinds of directives go in this namespace.
|
||||||
*/
|
*/
|
||||||
@ -339,6 +383,8 @@ class HTMLPurifier_ConfigEntity_Namespace extends HTMLPurifier_ConfigEntity {
|
|||||||
class HTMLPurifier_ConfigEntity_Directive extends HTMLPurifier_ConfigEntity
|
class HTMLPurifier_ConfigEntity_Directive extends HTMLPurifier_ConfigEntity
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var $class = 'directive';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash of value aliases, i.e. values that are equivalent.
|
* Hash of value aliases, i.e. values that are equivalent.
|
||||||
*/
|
*/
|
||||||
@ -385,4 +431,21 @@ class HTMLPurifier_ConfigEntity_Directive extends HTMLPurifier_ConfigEntity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Structure object describing a directive alias
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_ConfigEntity_DirectiveAlias extends HTMLPurifier_ConfigEntity
|
||||||
|
{
|
||||||
|
var $class = 'alias';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace being aliased to
|
||||||
|
*/
|
||||||
|
var $namespace;
|
||||||
|
/**
|
||||||
|
* Directive being aliased to
|
||||||
|
*/
|
||||||
|
var $name;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -251,6 +251,30 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase
|
|||||||
$this->assertError('Namespace name must be alphanumeric');
|
$this->assertError('Namespace name must be alphanumeric');
|
||||||
$this->assertNoErrors();
|
$this->assertNoErrors();
|
||||||
|
|
||||||
|
// alias related tests
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::defineNamespace('Home', 'Sweet home.');
|
||||||
|
HTMLPurifier_ConfigSchema::define('Home', 'Rug', 3, 'int', 'ID.');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||||
|
|
||||||
|
$this->expectError('Cannot define directive alias for undefined namespace');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Store', 'Rug', 'Home', 'Rug');
|
||||||
|
|
||||||
|
$this->expectError('Directive name must be alphanumeric');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'R.g', 'Home', 'Rug');
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::define('Home', 'Rugger', 'Bob Max', 'string', 'Name of.');
|
||||||
|
$this->expectError('Cannot define alias over directive');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Rugger', 'Home', 'Rug');
|
||||||
|
|
||||||
|
$this->expectError('Cannot define alias to undefined directive');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Rug2', 'Home', 'Rugavan');
|
||||||
|
|
||||||
|
$this->expectError('Cannot define alias to alias');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Rug2', 'Home', 'Carpet');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertValid($var, $type, $ret = null) {
|
function assertValid($var, $type, $ret = null) {
|
||||||
|
@ -199,6 +199,24 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testAliases() {
|
||||||
|
|
||||||
|
HTMLPurifier_ConfigSchema::defineNamespace('Home', 'Sweet home.');
|
||||||
|
HTMLPurifier_ConfigSchema::define('Home', 'Rug', 3, 'int', 'ID.');
|
||||||
|
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||||
|
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
|
||||||
|
$this->assertEqual($config->get('Home', 'Rug'), 3);
|
||||||
|
|
||||||
|
$this->expectError('Cannot get value from aliased directive, use real name');
|
||||||
|
$config->get('Home', 'Carpet');
|
||||||
|
|
||||||
|
$config->set('Home', 'Carpet', 999);
|
||||||
|
$this->assertEqual($config->get('Home', 'Rug'), 999);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user