mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-01 11:50:28 +02:00
[3.1.0]
- Add tests for the atoms. - Add Id validation for Directives git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1623 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -30,7 +30,6 @@ class HTMLPurifier_ConfigSchema_Validator
|
||||
public function validateNamespace($n) {
|
||||
$this->context = "namespace '{$n->namespace}'";
|
||||
$this->with($n, 'namespace')
|
||||
->assertIsString()
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
$this->with($n, 'description')
|
||||
@@ -40,12 +39,27 @@ class HTMLPurifier_ConfigSchema_Validator
|
||||
|
||||
public function validateDirective($d) {
|
||||
$this->context = "directive '{$d->id}'";
|
||||
$this->validateId($d->id);
|
||||
}
|
||||
|
||||
public function validateId($id) {
|
||||
$this->context = "id '$id'";
|
||||
$this->with($id, 'namespace')
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
$this->with($id, 'directive')
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
}
|
||||
|
||||
// protected helper functions
|
||||
|
||||
protected function with($obj, $member) {
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->interchange, $this->context, $obj, $member);
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->context, $obj, $member);
|
||||
}
|
||||
|
||||
protected function error($msg) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception($msg . ' in ' . $this->context);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,15 +3,15 @@
|
||||
/**
|
||||
* Fluent interface for validating the contents of member variables.
|
||||
* This should be immutable. See HTMLPurifier_ConfigSchema_Validator for
|
||||
* use-cases.
|
||||
* use-cases. We name this an 'atom' because it's ONLY for validations that
|
||||
* are independent and usually scalar.
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_ValidatorAtom
|
||||
{
|
||||
|
||||
protected $interchange, $context, $obj, $member, $contents;
|
||||
protected $context, $obj, $member, $contents;
|
||||
|
||||
public function __construct($interchange, $context, $obj, $member) {
|
||||
$this->interchange = $interchange;
|
||||
public function __construct($context, $obj, $member) {
|
||||
$this->context = $context;
|
||||
$this->obj = $obj;
|
||||
$this->member = $member;
|
||||
@@ -24,11 +24,12 @@ class HTMLPurifier_ConfigSchema_ValidatorAtom
|
||||
}
|
||||
|
||||
public function assertNotNull() {
|
||||
if (is_null($this->contents)) $this->error('must not be null');
|
||||
if ($this->contents === null) $this->error('must not be null');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function assertAlnum() {
|
||||
$this->assertIsString();
|
||||
if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
|
||||
return $this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user