diff --git a/inc/field/checkboxesfield.class.php b/inc/field/checkboxesfield.class.php index 218deffcf..dd294bf40 100644 --- a/inc/field/checkboxesfield.class.php +++ b/inc/field/checkboxesfield.class.php @@ -187,7 +187,6 @@ public function isValidValue($value): bool { return true; } - $value = Toolbox::stripslashes_deep($value); foreach ($value as $item) { if (trim($item) == '') { return false; diff --git a/inc/field/radiosfield.class.php b/inc/field/radiosfield.class.php index 314b4d644..07ec0daa1 100644 --- a/inc/field/radiosfield.class.php +++ b/inc/field/radiosfield.class.php @@ -205,7 +205,6 @@ public function isValidValue($value): bool { if ($value == '') { return true; } - $value = Toolbox::stripslashes_deep($value); $value = trim($value); return in_array($value, $this->getAvailableValues()); } diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php index bb861f97e..1f4aa2d47 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php @@ -95,37 +95,54 @@ public function providerIsValidValue() { ] ], ])); - return [ - [ - 'instance' => $instance, - 'value' => '', - 'expected' => true, - ], - [ - 'instance' => $instance, - 'value' => [], - 'expected' => true, - ], - [ - 'instance' => $instance, - 'value' => ['1'], - 'expected' => true, - ], - [ - 'instance' => $instance, - 'value' => ['1', '4'], - 'expected' => true, - ], - [ - 'instance' => $instance, - 'value' => ['1', '9'], - 'expected' => false, - ], - [ - 'instance' => $instance, - 'value' => ['9'], - 'expected' => false, + yield [ + 'instance' => $instance, + 'value' => '', + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => [], + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => ['1'], + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => ['1', '4'], + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => ['1', '9'], + 'expected' => false, + ]; + yield [ + 'instance' => $instance, + 'value' => ['9'], + 'expected' => false, + ]; + + // values are escaped by GLPI, then backslashes are doubled + $instance = $this->newTestedInstance($this->getQuestion([ + 'fieldtype' => 'checkboxes', + 'values' => implode('\r\n', ['X:\\\\path\\\\to\\\\file', 'nothing']), + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] ], + ])); + yield [ + 'instance' => $instance, + 'value' => ['X:\\path\\to\\file'], + 'expected' => true, ]; } diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php index 756c73557..53dc4ecd3 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/RadiosField.php @@ -100,6 +100,55 @@ public function testCanRequire() { $this->boolean($output)->isTrue(); } + public function providerIsValidValue() { + $instance = $this->newTestedInstance($this->getQuestion([ + 'fieldtype' => 'radios', + 'values' => implode('\r\n', ['1', '2', '3', '4']), + ])); + yield [ + 'instance' => $instance, + 'value' => '', + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => '1', + 'expected' => true, + ]; + yield [ + 'instance' => $instance, + 'value' => '9', + 'expected' => false, + ]; + + // values are escaped by GLPI, then backslashes are doubled + $instance = $this->newTestedInstance($this->getQuestion([ + 'fieldtype' => 'radios', + 'values' => implode('\r\n', ['X:\\\\path\\\\to\\\\file', 'nothing']), + '_parameters' => [ + 'checkboxes' => [ + 'range' => [ + 'range_min' => '', + 'range_max' => '', + ] + ] + ], + ])); + yield [ + 'instance' => $instance, + 'value' => 'X:\\path\\to\\file', + 'expected' => true, + ]; + } + + /** + * @dataProvider providerIsValidValue + */ + public function testIsValidValue($instance, $value, $expected) { + $output = $instance->isValidValue($value); + $this->boolean($output)->isEqualTo($expected); + } + public function providerSerializeValue() { $question = $this->getQuestion([ 'fieldtype' => 'radios',