From 970fe552c9162de2e18f04386422377265137c73 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 27 Jul 2022 11:18:03 +0200 Subject: [PATCH 1/2] fix: regex check on some fields broken --- inc/field/emailfield.class.php | 2 +- inc/field/floatfield.class.php | 2 +- inc/field/hiddenfield.class.php | 2 +- inc/field/hostnamefield.class.php | 2 +- inc/field/integerfield.class.php | 4 ---- inc/field/ipfield.class.php | 2 +- inc/field/textareafield.class.php | 2 +- 7 files changed, 6 insertions(+), 10 deletions(-) diff --git a/inc/field/emailfield.class.php b/inc/field/emailfield.class.php index 5dea74fca..68d0b9c7c 100644 --- a/inc/field/emailfield.class.php +++ b/inc/field/emailfield.class.php @@ -150,7 +150,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { diff --git a/inc/field/floatfield.class.php b/inc/field/floatfield.class.php index faa53a781..17c9f50b0 100644 --- a/inc/field/floatfield.class.php +++ b/inc/field/floatfield.class.php @@ -268,7 +268,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { diff --git a/inc/field/hiddenfield.class.php b/inc/field/hiddenfield.class.php index 00942d72a..c6aff20f3 100644 --- a/inc/field/hiddenfield.class.php +++ b/inc/field/hiddenfield.class.php @@ -140,7 +140,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { diff --git a/inc/field/hostnamefield.class.php b/inc/field/hostnamefield.class.php index 5b494aa2e..068b7e723 100644 --- a/inc/field/hostnamefield.class.php +++ b/inc/field/hostnamefield.class.php @@ -145,7 +145,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { diff --git a/inc/field/integerfield.class.php b/inc/field/integerfield.class.php index 85e4c292f..006b8aba2 100644 --- a/inc/field/integerfield.class.php +++ b/inc/field/integerfield.class.php @@ -150,10 +150,6 @@ public function greaterThan($value): bool { return ((int) $this->value) > ((int) $value); } - public function regex($value): bool { - return (preg_grep($value, (int) $this->value)) ? true : false; - } - public function getHtmlIcon() { return ''; } diff --git a/inc/field/ipfield.class.php b/inc/field/ipfield.class.php index c16cccb8a..bc8c34264 100644 --- a/inc/field/ipfield.class.php +++ b/inc/field/ipfield.class.php @@ -156,7 +156,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { diff --git a/inc/field/textareafield.class.php b/inc/field/textareafield.class.php index 7f6c12532..bfe604f12 100644 --- a/inc/field/textareafield.class.php +++ b/inc/field/textareafield.class.php @@ -240,7 +240,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_grep($value, $this->value)) ? true : false; + return (preg_match($value, $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool { From 3299a1eb973c3cee503d2e0d96d45773b8c4acad Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Wed, 27 Jul 2022 11:55:43 +0200 Subject: [PATCH 2/2] fix(textareafield): unsanitize before testing regex --- inc/field/textareafield.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/field/textareafield.class.php b/inc/field/textareafield.class.php index bfe604f12..0b89ddb5c 100644 --- a/inc/field/textareafield.class.php +++ b/inc/field/textareafield.class.php @@ -240,7 +240,7 @@ public function lessThan($value): bool { } public function regex($value): bool { - return (preg_match($value, $this->value) === 1) ? true : false; + return (preg_match(Sanitizer::unsanitize($value), $this->value) === 1) ? true : false; } public function isPublicFormCompatible(): bool {