Fix type issues with `AbstractNumericFormField::value()`
authorMatthias Schmidt <gravatronics@live.com>
Sun, 15 Apr 2018 10:33:40 +0000 (12:33 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 15 Apr 2018 10:33:40 +0000 (12:33 +0200)
See #2509

wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php

index 6b9a6ca75da022423e29ef78835b6098173137ef..ac1c466900f81a4651ad10e7a7a28af48a379383 100644 (file)
@@ -159,6 +159,15 @@ abstract class AbstractNumericFormField extends AbstractFormField implements IMa
         */
        public function value($value): IFormField {
                if ($value !== null) {
+                       if (is_string($value) && is_numeric($value)) {
+                               if (preg_match('~^\d+$~', $value)) {
+                                       $value = intval($value);
+                               }
+                               else {
+                                       $value = floatval($value);
+                               }
+                       }
+                       
                        if ($this->integerValues && !is_int($value)) {
                                throw new \InvalidArgumentException("Given value is neither `null` nor an int, " . gettype($value) . " given.");
                        }