mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +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;
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user