mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Refactor unit tests so that abstract test cases are now called Harnesses and AttrDef tests use their harness's assertDef() function, which enforces type much better. Also fixed a few bugs.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@161 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -6,11 +6,11 @@ require_once 'HTMLPurifier/Config.php';
|
||||
class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef
|
||||
{
|
||||
|
||||
function validate($raw_string, $config = null) {
|
||||
function validate($string, $config = null) {
|
||||
|
||||
if (!$config) $config = HTMLPurifier_Config::createDefault();
|
||||
|
||||
$string = trim($raw_string);
|
||||
$string = trim($string);
|
||||
|
||||
// early abort: '' and '0' (strings that convert to false) are invalid
|
||||
if (!$string) return false;
|
||||
@@ -23,18 +23,20 @@ class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef
|
||||
// and plus it would complicate optimization efforts (you never
|
||||
// see that anyway).
|
||||
$matches = array();
|
||||
$pattern = '/(?:\s|\A)'.
|
||||
'((?:-?[A-Za-z_]|--)[A-Za-z_\-0-9]*)'.
|
||||
'(?:\s|\z)/';
|
||||
$pattern = '/(?:(?<=\s)|\A)'.
|
||||
'((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'.
|
||||
'(?:(?=\s)|\z)/';
|
||||
preg_match_all($pattern, $string, $matches);
|
||||
|
||||
if (empty($matches[1])) return false;
|
||||
|
||||
$new_string = '';
|
||||
foreach ($matches[1] as $class_names) {
|
||||
$new_string .= $class_names . ' ';
|
||||
}
|
||||
$new_string = rtrim($new_string);
|
||||
|
||||
return ($new_string == $raw_string) ? true : $new_string ? $new_string : false;
|
||||
return $new_string;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -14,16 +14,14 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
||||
$this->case_sensitive = $case_sensitive;
|
||||
}
|
||||
|
||||
function validate($raw_string) {
|
||||
$string = trim($raw_string);
|
||||
function validate($string) {
|
||||
$string = trim($string);
|
||||
if (!$this->case_sensitive) {
|
||||
$string = ctype_lower($string) ? $string : strtolower($string);
|
||||
}
|
||||
$result = isset($this->valid_values[$string]);
|
||||
|
||||
// if strings equal, return result, otherwise, return
|
||||
// the new string on a good result and false on a bad one
|
||||
return ($string == $raw_string) ? $result : $result ? $string : false;
|
||||
return $result ? $string : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,9 +12,9 @@ require_once 'HTMLPurifier/IDAccumulator.php';
|
||||
class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
|
||||
{
|
||||
|
||||
function validate($old_id, $config, &$accumulator) {
|
||||
function validate($id, $config, &$accumulator) {
|
||||
|
||||
$id = trim($old_id); // trim it first
|
||||
$id = trim($id); // trim it first
|
||||
|
||||
if ($id === '') return false;
|
||||
if (isset($accumulator->ids[$id])) return false;
|
||||
@@ -37,7 +37,7 @@ class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
|
||||
// if no change was made to the ID, return the result
|
||||
// else, return the new id if stripping whitespace made it
|
||||
// valid, or return false.
|
||||
return ($id == $old_id) ? $result : ($result ? $id : false);
|
||||
return $result ? $id : false;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -6,8 +6,7 @@ class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef
|
||||
{
|
||||
|
||||
function validate($string) {
|
||||
$new_string = $this->parseCDATA($string);
|
||||
return ($string == $new_string) ? true : $new_string;
|
||||
return $this->parseCDATA($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,6 +26,15 @@ class HTMLPurifier_Config
|
||||
var $attr_class_blacklist = array();
|
||||
var $attr_class_whitelist = array();
|
||||
|
||||
// designate whether or not to allow numerals in language code subtags
|
||||
// RFC 1766, the current standard referenced by XML, does not permit
|
||||
// numbers, but,
|
||||
// RFC 3066, the superseding best practice standard since January 2001,
|
||||
// permits them.
|
||||
// we allow numbers by default, although you generally never see them
|
||||
// at all.
|
||||
var $attr_lang_alpha = false;
|
||||
|
||||
function createDefault() {
|
||||
$config = new HTMLPurifier_Config();
|
||||
return $config;
|
||||
|
Reference in New Issue
Block a user