mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-18 11:41:52 +00:00
Add HTMLPurifier_config->serialize()
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
parent
77b60a4206
commit
6e66dc9cad
3
NEWS
3
NEWS
@ -40,6 +40,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! You can now maintain your own configuration schema directories by
|
! You can now maintain your own configuration schema directories by
|
||||||
creating a config-schema.php file or passing an extra argument. Check
|
creating a config-schema.php file or passing an extra argument. Check
|
||||||
docs/dev-config-schema.html for more details.
|
docs/dev-config-schema.html for more details.
|
||||||
|
! Added HTMLPurifier_Config->serialize() method, which lets you save away
|
||||||
|
your configuration in a compact serial file, which you can unserialize
|
||||||
|
and use directly without having to go through the overhead of setup.
|
||||||
- Fix bug where URIDefinition would not get cleared if it's directives got
|
- Fix bug where URIDefinition would not get cleared if it's directives got
|
||||||
changed.
|
changed.
|
||||||
- Fix fatal error in HTMLPurifier_Encoder on certain platforms (probably NetBSD 5.0)
|
- Fix fatal error in HTMLPurifier_Encoder on certain platforms (probably NetBSD 5.0)
|
||||||
|
3
TODO
3
TODO
@ -20,9 +20,6 @@ afraid to cast your vote for the next feature to be implemented!
|
|||||||
- Think about allowing explicit order of operations hooks for transforms
|
- Think about allowing explicit order of operations hooks for transforms
|
||||||
- Add "register" field to config schemas to eliminate dependence on
|
- Add "register" field to config schemas to eliminate dependence on
|
||||||
naming conventions
|
naming conventions
|
||||||
- Make it easy for people to cache their entire configuration (so that
|
|
||||||
they have one script they run to change configuration, and then a stub
|
|
||||||
loader to get that configuration)
|
|
||||||
- Add examples to everything (make built-in which also automatically
|
- Add examples to everything (make built-in which also automatically
|
||||||
gives output)
|
gives output)
|
||||||
|
|
||||||
|
@ -564,6 +564,17 @@ class HTMLPurifier_Config
|
|||||||
trigger_error($msg . $extra, $no);
|
trigger_error($msg . $extra, $no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a serialized form of the configuration object that can
|
||||||
|
* be reconstituted.
|
||||||
|
*/
|
||||||
|
public function serialize() {
|
||||||
|
$this->getDefinition('HTML');
|
||||||
|
$this->getDefinition('CSS');
|
||||||
|
$this->getDefinition('URI');
|
||||||
|
return serialize($this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
// vim: et sw=4 sts=4
|
||||||
|
15
smoketests/cacheConfig.php
Normal file
15
smoketests/cacheConfig.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML.Doctype', 'HTML 4.01 Strict');
|
||||||
|
$config->set('HTML.Allowed', 'b,a[href],br');
|
||||||
|
$config->set('CSS.AllowTricky', true);
|
||||||
|
$config->set('URI.Disable', true);
|
||||||
|
$serial = $config->serialize();
|
||||||
|
|
||||||
|
$result = unserialize($serial);
|
||||||
|
$purifier = new HTMLPurifier($result);
|
||||||
|
echo htmlspecialchars($purifier->purify('<b>Bold</b><br><i><a href="http://google.com">no</a> formatting</i>'));
|
||||||
|
|
@ -451,6 +451,13 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
|||||||
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
|
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSerialize() {
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
$config->set('HTML.Allowed', 'a');
|
||||||
|
$config2 = unserialize($config->serialize());
|
||||||
|
$this->assertIdentical($config, $config2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
// vim: et sw=4 sts=4
|
||||||
|
Loading…
Reference in New Issue
Block a user