From c17136ab2c0dc310e082aaa26b0e4ea1c0546d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Thu, 4 Jun 2020 12:17:27 +0200 Subject: [PATCH] :ambulance: fix(core) Improve formating for invalid value error POC for html escaping of translated errors. issue #6071 --- include/errors/class_SimplePluginCheckError.inc | 16 ++++++++++++++++ .../attributes/class_IntAttribute.inc | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/errors/class_SimplePluginCheckError.inc b/include/errors/class_SimplePluginCheckError.inc index de9772773..c9679e4b3 100644 --- a/include/errors/class_SimplePluginCheckError.inc +++ b/include/errors/class_SimplePluginCheckError.inc @@ -83,4 +83,20 @@ class SimplePluginCheckError extends FusionDirectoryError return [_('Error'), $html, ERROR_DIALOG, $trace]; } + + /*! + * \brief Format error message for invalid value + * + * \param string $error The unescaped text error + * + * \return HTML string + */ + static public function invalidValue(string $error): string + { + return sprintf( + '<b>%s</b> %s', + htmlescape(_('Invalid value:')), + htmlescape($error) + ); + } } diff --git a/include/simpleplugin/attributes/class_IntAttribute.inc b/include/simpleplugin/attributes/class_IntAttribute.inc index bcbfc7008..b5218747a 100644 --- a/include/simpleplugin/attributes/class_IntAttribute.inc +++ b/include/simpleplugin/attributes/class_IntAttribute.inc @@ -81,13 +81,22 @@ class IntAttribute extends Attribute return $error; } elseif ($this->value !== '') { if (!is_numeric($this->value)) { - return new SimplePluginCheckError($this, sprintf(_('"%s" is not an number'), $this->getValue())); + return new SimplePluginCheckError( + $this, + SimplePluginCheckError::invalidValue(sprintf(_('"%s" is not an number'), $this->getValue())) + ); } if (($this->min !== FALSE) && ($this->value < $this->min)) { - return new SimplePluginCheckError($this, sprintf(_('%s is smaller than %s'), $this->getValue(), $this->min)); + return new SimplePluginCheckError( + $this, + SimplePluginCheckError::invalidValue(sprintf(_('%s is smaller than %s'), $this->getValue(), $this->min)) + ); } if (($this->max !== FALSE) && ($this->value > $this->max)) { - return new SimplePluginCheckError($this, sprintf(_('%s is larger than %s'), $this->getValue(), $this->max)); + return new SimplePluginCheckError( + $this, + SimplePluginCheckError::invalidValue(sprintf(_('%s is larger than %s'), $this->getValue(), $this->max)) + ); } } } -- GitLab