mvc: CSVListField validation message update

MaskPerItem=Y needs work and the preg_match() shoudldn't be used
to look inside the match which creates the initial problem:

/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php:176:
Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php:162 - Undefined array key 0 (errno=2)
This commit is contained in:
Franco Fichtner 2023-09-22 12:55:36 +02:00
parent 5d89666946
commit 90c5db7687

View File

@ -42,11 +42,6 @@ class CSVListField extends BaseField
*/
protected $internalIsContainer = false;
/**
* @var string default validation message string
*/
protected $internalValidationMessage = "list validation error";
/**
* item separator
* @var string
@ -69,6 +64,15 @@ class CSVListField extends BaseField
*/
protected $internalMaskPerItem = false;
/**
* {@inheritdoc}
*/
protected function defaultValidationMessage()
{
return gettext('List validation error.');
}
/**
* set validation mask
* @param string $value regexp validation mask
@ -162,12 +166,12 @@ class CSVListField extends BaseField
$items = explode($this->separatorchar, $this->internalValue);
foreach ($items as $item) {
if (!$regex_match($item, $this->internalMask)) {
return ["\"" . $item . "\" is invalid. " . $this->internalValidationMessage];
return ["\"" . $item . "\" is invalid. " . $this->getValidationMessage()];
}
}
} else {
if (!$regex_match($this->internalValue, $this->internalMask)) {
return [$this->internalValidationMessage];
return [$this->getValidationMessage()];
}
}
return [];