From 06206e039d37d05f7e00ae3f78980e0bb4415a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Wed, 17 Oct 2018 11:04:36 +0200 Subject: [PATCH] :sparkles: feat(MacAttribute) Use pattern HTML5 attribute for Mac Address as well issue #5910 --- include/class_tests.inc | 2 +- include/simpleplugin/class_helpersAttribute.inc | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/class_tests.inc b/include/class_tests.inc index 2dc73fdf8..93d909123 100644 --- a/include/class_tests.inc +++ b/include/class_tests.inc @@ -166,7 +166,7 @@ class tests */ public static function is_mac($mac) { - return preg_match("/^[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$/i", $mac); + return preg_match('/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/', $mac); } diff --git a/include/simpleplugin/class_helpersAttribute.inc b/include/simpleplugin/class_helpersAttribute.inc index e4211e8a5..f2538d012 100644 --- a/include/simpleplugin/class_helpersAttribute.inc +++ b/include/simpleplugin/class_helpersAttribute.inc @@ -118,16 +118,14 @@ class MacAddressAttribute extends StringAttribute { protected $trim = TRUE; - function setValue ($value) + function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = '', $acl = '') { - return parent::setValue(strtolower($value)); + parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl, '/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/', '5E:FF:56:A2:AF:15'); } - function validate () + function setValue ($value) { - if (!tests::is_mac($this->value)) { - return msgPool::invalid($this->getLabel(), $this->value); - } + return parent::setValue(strtolower($value)); } } -- GitLab