Skip to content

Commit 0dd48a5

Browse files
committed
fix(validator): trim and deduplicate options in validateOptions
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 98f5bf9 commit 0dd48a5

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/Service/FieldDefinitionValidator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,20 @@ private function validateOptions(string $type, mixed $options): ?array {
9696
throw new InvalidArgumentException('select fields require at least one option');
9797
}
9898

99+
$normalized = [];
99100
foreach ($options as $option) {
100101
if (!is_string($option) || trim($option) === '') {
101102
throw new InvalidArgumentException('each option must be a non-empty string');
102103
}
104+
$normalized[] = trim($option);
103105
}
104106

105-
return array_values($options);
107+
$deduplicated = array_values(array_unique($normalized));
108+
if (count($deduplicated) !== count($normalized)) {
109+
throw new InvalidArgumentException('options must not contain duplicate values');
110+
}
111+
112+
return $deduplicated;
106113
}
107114

108115
/**

0 commit comments

Comments
 (0)