diff --git a/library/HTMLPurifier/ConfigSchema/Interchange.php b/library/HTMLPurifier/ConfigSchema/Interchange.php index 1ae4330b..4fbde069 100644 --- a/library/HTMLPurifier/ConfigSchema/Interchange.php +++ b/library/HTMLPurifier/ConfigSchema/Interchange.php @@ -32,7 +32,7 @@ class HTMLPurifier_ConfigSchema_Interchange * Adds a directive array to $directives */ public function addDirective($directive) { - if (isset($this->directives[$i = "{$directive->id}"])) { + if (isset($this->directives[$i = $directive->id->toString()])) { throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'"); } $this->directives[$i] = $directive; diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Id.php b/library/HTMLPurifier/ConfigSchema/Interchange/Id.php index bb1d6ff3..40a5fe3c 100644 --- a/library/HTMLPurifier/ConfigSchema/Interchange/Id.php +++ b/library/HTMLPurifier/ConfigSchema/Interchange/Id.php @@ -13,7 +13,11 @@ class HTMLPurifier_ConfigSchema_Interchange_Id $this->directive = $directive; } - public function __toString() { + /** + * @warning This is NOT magic, to ensure that people don't abuse SPL and + * cause problems for PHP 5.0 support. + */ + public function toString() { return $this->namespace . '.' . $this->directive; } diff --git a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php index 4723b1d5..2b2c9ab4 100644 --- a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php +++ b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php @@ -43,20 +43,21 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder // These are required elements: $directive->id = $this->id($hash->offsetGet('ID')); + $id = $directive->id->toString(); // convenience if (isset($hash['TYPE'])) { $type = explode('/', $hash->offsetGet('TYPE')); if (isset($type[1])) $directive->typeAllowsNull = true; $directive->type = $type[0]; } else { - throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '{$directive->id}' not defined"); + throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined"); } if (isset($hash['DEFAULT'])) { try { $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull); } catch (HTMLPurifier_VarParserException $e) { - throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in TYPE/DEFAULT in directive hash '{$directive->id}'"); + throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in TYPE/DEFAULT in directive hash '$id'"); } } @@ -79,7 +80,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder $this->varParser->parse($real, $directive->type, $directive->typeAllowsNull); } } catch (HTMLPurifier_VarParserException $e) { - throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in $alias => $real in VALUE-ALIASES in directive hash '{$directive->id}'"); + throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in $alias => $real in VALUE-ALIASES in directive hash '$id'"); } } diff --git a/library/HTMLPurifier/ConfigSchema/Validator.php b/library/HTMLPurifier/ConfigSchema/Validator.php index c7b29f37..5130ad52 100644 --- a/library/HTMLPurifier/ConfigSchema/Validator.php +++ b/library/HTMLPurifier/ConfigSchema/Validator.php @@ -40,7 +40,8 @@ class HTMLPurifier_ConfigSchema_Validator $this->validateNamespace($namespace); } foreach ($interchange->directives as $i => $directive) { - if ($i != "{$directive->id}") $this->error(false, "Integrity violation: key '$i' does not match internal id '{$directive->id}'"); + $id = $directive->id->toString(); + if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'"); $this->validateDirective($directive); } } @@ -57,7 +58,8 @@ class HTMLPurifier_ConfigSchema_Validator } public function validateId($id) { - $this->context[] = "id '$id'"; + $id_string = $id->toString(); + $this->context[] = "id '$id_string'"; if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) { // handled by InterchangeBuilder $this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id'); @@ -72,7 +74,8 @@ class HTMLPurifier_ConfigSchema_Validator } public function validateDirective($d) { - $this->context[] = "directive '{$d->id}'"; + $id = $d->id->toString(); + $this->context[] = "directive '$id'"; $this->validateId($d->id); $this->with($d, 'description') ->assertNotEmpty(); diff --git a/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php b/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php index 78456bc4..f5fa49e0 100644 --- a/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php +++ b/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php @@ -40,20 +40,6 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase $this->validator->validate($this->interchange); } - public function testDirectiveIdInstanceof() { - // This example is somewhat contrived - $this->makeNamespace('Ns'); - $d = new HTMLPurifier_ConfigSchema_Interchange_Directive(); - $d->id = 3; - $d->default = 0; - $d->type = 'int'; - $d->description = 'Description'; - $this->interchange->addDirective($d); - - $this->expectValidationException("Id '3' in directive '3' is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id"); - $this->validator->validate($this->interchange); - } - public function testDirectiveTypeNotEmpty() { $this->makeNamespace('Ns'); $d = $this->makeDirective('Ns', 'Dir');