mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 00:41:52 +00:00
[3.1.0] Move ConfigSchema to HTMLPurifier core
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1576 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
d3c04de9dc
commit
002fe649f7
16
TODO
16
TODO
@ -17,8 +17,6 @@ UPCOMING RELEASE
|
|||||||
|
|
||||||
IMPORTANT
|
IMPORTANT
|
||||||
- Release candidate, because of the major changes
|
- Release candidate, because of the major changes
|
||||||
- Move utility classes for ConfigSchema into HTML Purifier itself: they're
|
|
||||||
that important
|
|
||||||
|
|
||||||
DOCUMENTATION
|
DOCUMENTATION
|
||||||
- Document new ConfigSchema setup and format; dev-includes.txt is a base
|
- Document new ConfigSchema setup and format; dev-includes.txt is a base
|
||||||
@ -31,21 +29,21 @@ IMPORTANT FEATURES
|
|||||||
- Factor generate-schema-cache.php into a class, so that the maintenance script
|
- Factor generate-schema-cache.php into a class, so that the maintenance script
|
||||||
is as small as possible
|
is as small as possible
|
||||||
- Factor out command line parser into its own class, and unit test it
|
- Factor out command line parser into its own class, and unit test it
|
||||||
- Optimize ConfigSchema by only caching things necessary for runtime
|
- Optimize ConfigSchema by making our runtime class only contain entries for
|
||||||
|
things necessary for operation (NOT descriptions).
|
||||||
|
|
||||||
CONFIGDOC
|
CONFIGDOC
|
||||||
- Properly integrate new ConfigSchema system into configdoc (Configdoc
|
- Properly integrate new ConfigSchema system into configdoc. DESCRIPTIONS
|
||||||
|
ARE CURRENTLY BROKEN AND NEED TO BE FIXED!!! (Configdoc
|
||||||
should directly read the configuration files, or at the very least should
|
should directly read the configuration files, or at the very least should
|
||||||
not use static functions)
|
not use static functions)
|
||||||
- Reduce code duplication between Serializer and Adapter/ReverseAdapter
|
- Deprecate Serializer in favor of ReverseAdapter
|
||||||
(we probably want to use ReverseAdapter for the long haul)
|
|
||||||
- Have configdoc use version and deprecated information (hide deprecated
|
- Have configdoc use version and deprecated information (hide deprecated
|
||||||
info, for example)
|
info, for example)
|
||||||
- Implement file sniffing for configdoc, so we can easily figure out
|
- Implement source code sniffing for configdoc, so we can easily figure out
|
||||||
which files use what configuration
|
which files use what configuration (we'll rely on the $config convention)
|
||||||
|
|
||||||
IF IT AIN'T BROKE...
|
IF IT AIN'T BROKE...
|
||||||
- Simplify merge library script by removing recursion? (or other things)
|
|
||||||
- Perhaps replace types with integer identifiers in ConfigSchema? (would be
|
- Perhaps replace types with integer identifiers in ConfigSchema? (would be
|
||||||
smaller, but not by much).
|
smaller, but not by much).
|
||||||
|
|
||||||
|
@ -16,8 +16,7 @@ class HTMLPurifierExtras
|
|||||||
|
|
||||||
public static function getPath($class) {
|
public static function getPath($class) {
|
||||||
if (
|
if (
|
||||||
strncmp('FSTools', $class, 7) !== 0 &&
|
strncmp('FSTools', $class, 7) !== 0
|
||||||
strncmp('ConfigSchema', $class, 12) !== 0
|
|
||||||
) return false;
|
) return false;
|
||||||
// Custom implementations can go here
|
// Custom implementations can go here
|
||||||
// Standard implementation:
|
// Standard implementation:
|
||||||
|
@ -28,12 +28,3 @@ the filesystem. It currently consists of two classes:
|
|||||||
method imaginable one would need.
|
method imaginable one would need.
|
||||||
|
|
||||||
Check the files themselves for more information.
|
Check the files themselves for more information.
|
||||||
|
|
||||||
|
|
||||||
ConfigSchema
|
|
||||||
------------
|
|
||||||
|
|
||||||
ConfigSchema is the next-generation configuration validation system for
|
|
||||||
HTML Purifier, built off of the original HTMLPurifier_ConfigSchema. When
|
|
||||||
complete, it will be used to generate schema files which will then be used
|
|
||||||
to enforce values set to HTMLPurifier_Config.
|
|
||||||
|
@ -121,6 +121,10 @@ require 'HTMLPurifier/ChildDef/Table.php';
|
|||||||
require 'HTMLPurifier/ConfigDef/Directive.php';
|
require 'HTMLPurifier/ConfigDef/Directive.php';
|
||||||
require 'HTMLPurifier/ConfigDef/DirectiveAlias.php';
|
require 'HTMLPurifier/ConfigDef/DirectiveAlias.php';
|
||||||
require 'HTMLPurifier/ConfigDef/Namespace.php';
|
require 'HTMLPurifier/ConfigDef/Namespace.php';
|
||||||
|
require 'HTMLPurifier/ConfigSchema/StringHash.php';
|
||||||
|
require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php';
|
||||||
|
require 'HTMLPurifier/ConfigSchema/StringHashParser.php';
|
||||||
|
require 'HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php';
|
||||||
require 'HTMLPurifier/DefinitionCache/Decorator.php';
|
require 'HTMLPurifier/DefinitionCache/Decorator.php';
|
||||||
require 'HTMLPurifier/DefinitionCache/Null.php';
|
require 'HTMLPurifier/DefinitionCache/Null.php';
|
||||||
require 'HTMLPurifier/DefinitionCache/Serializer.php';
|
require 'HTMLPurifier/DefinitionCache/Serializer.php';
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* of PHP 5, you must not use the $hash[$key] syntax; if you do
|
* of PHP 5, you must not use the $hash[$key] syntax; if you do
|
||||||
* our version of offsetGet is never called.
|
* our version of offsetGet is never called.
|
||||||
*/
|
*/
|
||||||
class ConfigSchema_StringHash extends ArrayObject
|
class HTMLPurifier_ConfigSchema_StringHash extends ArrayObject
|
||||||
{
|
{
|
||||||
protected $accessed = array();
|
protected $accessed = array();
|
||||||
|
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an array of keys to strings, probably generated by
|
* Takes an array of keys to strings, probably generated by
|
||||||
* ConfigSchema_StringHashParser
|
* HTMLPurifier_ConfigSchema_StringHashParser
|
||||||
*/
|
*/
|
||||||
class ConfigSchema_StringHashAdapter
|
class HTMLPurifier_ConfigSchema_StringHashAdapter
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,8 +13,8 @@ class ConfigSchema_StringHashAdapter
|
|||||||
*/
|
*/
|
||||||
public function adapt($hash, $schema) {
|
public function adapt($hash, $schema) {
|
||||||
|
|
||||||
if (! $hash instanceof ConfigSchema_StringHash) {
|
if (! $hash instanceof HTMLPurifier_ConfigSchema_StringHash) {
|
||||||
$hash = new ConfigSchema_StringHash($hash);
|
$hash = new HTMLPurifier_ConfigSchema_StringHash($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($hash['ID'])) {
|
if (!isset($hash['ID'])) {
|
@ -26,19 +26,18 @@
|
|||||||
* Put this in its own class hierarchy or something; this class
|
* Put this in its own class hierarchy or something; this class
|
||||||
* is usage agnostic.
|
* is usage agnostic.
|
||||||
*/
|
*/
|
||||||
class ConfigSchema_StringHashParser
|
class HTMLPurifier_ConfigSchema_StringHashParser
|
||||||
{
|
{
|
||||||
|
|
||||||
public $default = 'ID';
|
public $default = 'ID';
|
||||||
|
|
||||||
public function parseFile($file) {
|
public function parseFile($file) {
|
||||||
if (is_string($file)) $file = new FSTools_File($file);
|
if (!file_exists($file)) throw new Exception('File does not exist');
|
||||||
if (!$file->exists()) throw new Exception('File does not exist');
|
$fh = fopen($file, 'r');
|
||||||
$file->open('r');
|
|
||||||
$state = false;
|
$state = false;
|
||||||
$single = false;
|
$single = false;
|
||||||
$ret = array();
|
$ret = array();
|
||||||
while (($line = $file->getLine()) !== false) {
|
while (($line = fgets($fh)) !== false) {
|
||||||
$line = rtrim($line, "\n\r");
|
$line = rtrim($line, "\n\r");
|
||||||
if (!$state && $line === '') continue;
|
if (!$state && $line === '') continue;
|
||||||
if (strncmp('--', $line, 2) === 0) {
|
if (strncmp('--', $line, 2) === 0) {
|
||||||
@ -64,7 +63,7 @@ class ConfigSchema_StringHashParser
|
|||||||
$ret[$state] .= "$line\n";
|
$ret[$state] .= "$line\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file->close();
|
fclose($fh);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
* Converts HTMLPurifier_ConfigSchema into a StringHash which can be
|
* Converts HTMLPurifier_ConfigSchema into a StringHash which can be
|
||||||
* easily saved to a file.
|
* easily saved to a file.
|
||||||
*/
|
*/
|
||||||
class ConfigSchema_StringHashReverseAdapter
|
class HTMLPurifier_ConfigSchema_StringHashReverseAdapter
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $schema;
|
protected $schema;
|
@ -21,7 +21,7 @@ $namespaces = array();
|
|||||||
$directives = array();
|
$directives = array();
|
||||||
|
|
||||||
// Generate string hashes
|
// Generate string hashes
|
||||||
$parser = new ConfigSchema_StringHashParser();
|
$parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$hash = $parser->parseFile($file);
|
$hash = $parser->parseFile($file);
|
||||||
if (strpos($hash['ID'], '.') === false) {
|
if (strpos($hash['ID'], '.') === false) {
|
||||||
@ -31,7 +31,7 @@ foreach ($files as $file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter = new ConfigSchema_StringHashAdapter();
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter();
|
||||||
$schema = new HTMLPurifier_ConfigSchema();
|
$schema = new HTMLPurifier_ConfigSchema();
|
||||||
|
|
||||||
foreach ($namespaces as $hash) $adapter->adapt($hash, $schema);
|
foreach ($namespaces as $hash) $adapter->adapt($hash, $schema);
|
||||||
|
@ -58,7 +58,7 @@ function saveHash($hash) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$schema = HTMLPurifier_ConfigSchema::instance();
|
$schema = HTMLPurifier_ConfigSchema::instance();
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($schema);
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema);
|
||||||
|
|
||||||
foreach ($schema->info as $ns => $ns_array) {
|
foreach ($schema->info as $ns => $ns_array) {
|
||||||
saveHash($adapter->get($ns));
|
saveHash($adapter->get($ns));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
class HTMLPurifier_ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
function __construct() {
|
function __construct() {
|
||||||
generate_mock_once('HTMLPurifier_ConfigSchema');
|
generate_mock_once('HTMLPurifier_ConfigSchema');
|
||||||
@ -15,7 +15,7 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
|||||||
if (!isset($called[$func])) $called[$func] = 0;
|
if (!isset($called[$func])) $called[$func] = 0;
|
||||||
$schema->expectAt($called[$func]++, $func, $params);
|
$schema->expectAt($called[$func]++, $func, $params);
|
||||||
}
|
}
|
||||||
$adapter = new ConfigSchema_StringHashAdapter();
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter();
|
||||||
$adapter->adapt($input, $schema);
|
$adapter->adapt($input, $schema);
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* @note Sample input files are located in the StringHashParser/ directory.
|
* @note Sample input files are located in the StringHashParser/ directory.
|
||||||
*/
|
*/
|
||||||
class ConfigSchema_StringHashParserTest extends UnitTestCase
|
class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +12,7 @@ class ConfigSchema_StringHashParserTest extends UnitTestCase
|
|||||||
protected $parser;
|
protected $parser;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
$this->parser = new ConfigSchema_StringHashParser();
|
$this->parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
class HTMLPurifier_ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
function makeSchema() {
|
function makeSchema() {
|
||||||
@ -17,7 +17,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testNamespace() {
|
function testNamespace() {
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
$result = $adapter->get('Ns');
|
$result = $adapter->get('Ns');
|
||||||
$expect = array(
|
$expect = array(
|
||||||
'ID' => 'Ns',
|
'ID' => 'Ns',
|
||||||
@ -27,14 +27,14 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testBadNamespace() {
|
function testBadNamespace() {
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
$this->expectError("Namespace 'BadNs' doesn't exist in schema");
|
$this->expectError("Namespace 'BadNs' doesn't exist in schema");
|
||||||
$adapter->get('BadNs');
|
$adapter->get('BadNs');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirective() {
|
function testDirective() {
|
||||||
|
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
|
|
||||||
$result = $adapter->get('Ns', 'Dir');
|
$result = $adapter->get('Ns', 'Dir');
|
||||||
$expect = array(
|
$expect = array(
|
||||||
@ -53,13 +53,13 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testBadDirective() {
|
function testBadDirective() {
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
$this->expectError("Directive 'BadNs.BadDir' doesn't exist in schema");
|
$this->expectError("Directive 'BadNs.BadDir' doesn't exist in schema");
|
||||||
$adapter->get('BadNs', 'BadDir');
|
$adapter->get('BadNs', 'BadDir');
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertMethod($func, $input, $expect) {
|
function assertMethod($func, $input, $expect) {
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
$result = $adapter->$func($input);
|
$result = $adapter->$func($input);
|
||||||
$this->assertIdentical($result, $expect);
|
$this->assertIdentical($result, $expect);
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assertExtraction($desc, $expect_desc, $expect_version) {
|
function assertExtraction($desc, $expect_desc, $expect_version) {
|
||||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||||
list($result_desc, $result_version) = $adapter->extractVersion($desc);
|
list($result_desc, $result_version) = $adapter->extractVersion($desc);
|
||||||
$this->assertIdentical($result_desc, $expect_desc);
|
$this->assertIdentical($result_desc, $expect_desc);
|
||||||
$this->assertIdentical($result_version, $expect_version);
|
$this->assertIdentical($result_version, $expect_version);
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ConfigSchema_StringHashTest extends UnitTestCase
|
class HTMLPurifier_ConfigSchema_StringHashTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testUsed() {
|
public function testUsed() {
|
||||||
$hash = new ConfigSchema_StringHash(array(
|
$hash = new HTMLPurifier_ConfigSchema_StringHash(array(
|
||||||
'key' => 'value',
|
'key' => 'value',
|
||||||
'key2' => 'value2'
|
'key2' => 'value2'
|
||||||
));
|
));
|
@ -64,6 +64,10 @@ $test_files[] = 'HTMLPurifier/ChildDef/RequiredTest.php';
|
|||||||
$test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php';
|
$test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php';
|
||||||
$test_files[] = 'HTMLPurifier/ChildDef/TableTest.php';
|
$test_files[] = 'HTMLPurifier/ChildDef/TableTest.php';
|
||||||
$test_files[] = 'HTMLPurifier/ConfigSchemaTest.php';
|
$test_files[] = 'HTMLPurifier/ConfigSchemaTest.php';
|
||||||
|
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashAdapterTest.php';
|
||||||
|
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php';
|
||||||
|
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashParserTest.php';
|
||||||
|
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashTest.php';
|
||||||
$test_files[] = 'HTMLPurifier/ConfigTest.php';
|
$test_files[] = 'HTMLPurifier/ConfigTest.php';
|
||||||
$test_files[] = 'HTMLPurifier/ContextTest.php';
|
$test_files[] = 'HTMLPurifier/ContextTest.php';
|
||||||
$test_files[] = 'HTMLPurifier/DefinitionCacheFactoryTest.php';
|
$test_files[] = 'HTMLPurifier/DefinitionCacheFactoryTest.php';
|
||||||
@ -136,13 +140,6 @@ if ($csstidy_location) {
|
|||||||
|
|
||||||
$test_files[] = 'FSTools/FileTest.php';
|
$test_files[] = 'FSTools/FileTest.php';
|
||||||
|
|
||||||
// ConfigSchema auxiliary library
|
|
||||||
|
|
||||||
$test_files[] = 'ConfigSchema/StringHashAdapterTest.php';
|
|
||||||
$test_files[] = 'ConfigSchema/StringHashReverseAdapterTest.php';
|
|
||||||
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
|
||||||
$test_files[] = 'ConfigSchema/StringHashTest.php';
|
|
||||||
|
|
||||||
} // end if ($AC['only-phpt'])
|
} // end if ($AC['only-phpt'])
|
||||||
|
|
||||||
// PHPT tests
|
// PHPT tests
|
||||||
|
Loading…
Reference in New Issue
Block a user