From 90c5db768767922bd5686b0fbca9c3b8bcd15c16 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 22 Sep 2023 12:55:36 +0200 Subject: [PATCH] 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) --- .../OPNsense/Base/FieldTypes/CSVListField.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php index 69a90200f..037d147b1 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php @@ -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 [];