Commit 7394f17c authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch 'backport-5807' into '1.2-fixes'

:ambulance: fix(simpleplugin) Throw Exceptions when attributes are set to non-compatible types

See merge request fusiondirectory/fd!198
Showing with 34 additions and 0 deletions
+34 -0
......@@ -38,6 +38,13 @@ class LDIFImportException extends FusionDirectoryException {}
*/
class LdapGeneralizedTimeBadFormatException extends FusionDirectoryException {}
/*! \class InvalidValueException
\brief Exception class which can be thrown if an attribute is set to a value with a non-compatible type
*/
class InvalidValueException extends FusionDirectoryException
{
}
class NonExistingObjectTypeException extends FusionDirectoryException {}
class NonExistingBranchException extends FusionDirectoryException {}
class NonExistingLdapNodeException extends FusionDirectoryException {}
......
......@@ -118,6 +118,13 @@ class BaseSelectorAttribute extends Attribute
}
}
function checkValue($value)
{
if (!is_string($value) && (!is_object($value) || !method_exists($value, '__toString' ))) {
throw new InvalidValueException(_('Base field value should always be a string'));
}
}
function setValue ($value)
{
parent::setValue($value);
......
......@@ -339,6 +339,13 @@ class SetAttribute extends Attribute
{
$this->size = $size;
}
function checkValue($value)
{
if (!is_array($value)) {
throw new InvalidValueException(sprintf(_('SetAttribute "%s" was set to a non-compatible value'), $this->getLabel()));
}
}
}
class OrderedArrayAttribute extends SetAttribute
......
......@@ -107,6 +107,13 @@ class StringAttribute extends Attribute
return $this->autocomplete;
}
function checkValue($value)
{
if (!is_scalar($value) && (!is_object($value) || !method_exists($value, '__toString' ))) {
throw new InvalidValueException(sprintf(_('StringAttribute "%s" was set to a non-compatible value'), $this->getLabel()));
}
}
function setValue ($value)
{
if ($this->trim) {
......
......@@ -149,8 +149,14 @@ class Attribute
return $this->inLdap;
}
function checkValue ($value)
{
/* Should throw InvalidValueException if needed */
}
function setValue ($value)
{
$this->checkValue($value);
$old_value = $this->value;
$this->value = $value;
if (($this->submitForm != FALSE) && ($this->submitForm !== TRUE) && ($old_value != $value) && is_object($this->plugin)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment