Skip to content

Commit 706b70f

Browse files
committed
fix(selectfield): too many unescaping
1 parent f357d9c commit 706b70f

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

inc/field/selectfield.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public function isValidValue($value): bool {
116116
if ($value == '0') {
117117
return true;
118118
}
119-
$value = Toolbox::stripslashes_deep($value);
120119
$value = trim($value);
121120
return in_array($value, $this->getAvailableValues());
122121
}

tests/3-unit/GlpiPlugin/Formcreator/Field/SelectField.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,55 @@ public function testGetEmptyParameters() {
252252
->isIdenticalTo([]);
253253
}
254254

255+
public function providerIsValidValue() {
256+
$instance = $this->newTestedInstance($this->getQuestion([
257+
'fieldtype' => 'select',
258+
'values' => implode('\r\n', ['1', '2', '3', '4']),
259+
]));
260+
yield [
261+
'instance' => $instance,
262+
'value' => '',
263+
'expected' => false,
264+
];
265+
yield [
266+
'instance' => $instance,
267+
'value' => '1',
268+
'expected' => true,
269+
];
270+
yield [
271+
'instance' => $instance,
272+
'value' => '9',
273+
'expected' => false,
274+
];
275+
276+
// values are escaped by GLPI, then backslashes are doubled
277+
$instance = $this->newTestedInstance($this->getQuestion([
278+
'fieldtype' => 'select',
279+
'values' => implode('\r\n', ['X:\\\\path\\\\to\\\\file', 'nothing']),
280+
'_parameters' => [
281+
'checkboxes' => [
282+
'range' => [
283+
'range_min' => '',
284+
'range_max' => '',
285+
]
286+
]
287+
],
288+
]));
289+
yield [
290+
'instance' => $instance,
291+
'value' => 'X:\\path\\to\\file',
292+
'expected' => true,
293+
];
294+
}
295+
296+
/**
297+
* @dataProvider providerIsValidValue
298+
*/
299+
public function testIsValidValue($instance, $value, $expected) {
300+
$output = $instance->isValidValue($value);
301+
$this->boolean($output)->isEqualTo($expected);
302+
}
303+
255304
public function providerSerializeValue() {
256305
return [
257306
[

0 commit comments

Comments
 (0)