mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
[3.1.0] Implement Duplicate validator, also modify some design things
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1596 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -15,7 +15,7 @@ class HTMLPurifier_ConfigSchema_Validator_Alnum extends HTMLPurifier_ConfigSchem
|
||||
|
||||
public function validate(&$arr, $interchange) {
|
||||
if (!ctype_alnum($arr[$this->index])) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception($arr[$this->index] . ' in '. $this->index .' must be alphanumeric');
|
||||
$this->error($arr[$this->index] . ' in '. $this->index .' must be alphanumeric');
|
||||
}
|
||||
}
|
||||
|
||||
|
21
library/HTMLPurifier/ConfigSchema/Validator/Duplicate.php
Normal file
21
library/HTMLPurifier/ConfigSchema/Validator/Duplicate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validates that this ID does not exist already in the interchange object.
|
||||
* @note
|
||||
* Although this tests both possible values, in practice the ID
|
||||
* will only be in one or the other. We do this to keep things simple.
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_Validator_Duplicate extends HTMLPurifier_ConfigSchema_Validator
|
||||
{
|
||||
|
||||
public function validate(&$arr, $interchange) {
|
||||
if (isset($interchange->namespaces[$arr['ID']])) {
|
||||
$this->error('Cannot redefine namespace');
|
||||
}
|
||||
if (isset($interchange->directives[$arr['ID']])) {
|
||||
$this->error('Cannot redefine directive');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -14,7 +14,7 @@ class HTMLPurifier_ConfigSchema_Validator_Exists extends HTMLPurifier_ConfigSche
|
||||
|
||||
public function validate(&$arr, $interchange) {
|
||||
if (empty($arr[$this->index])) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception($this->index . ' must exist');
|
||||
$this->error($this->index . ' must exist');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user