SelectChoiceValidator should probably disallow negative choices
bhaveshpraveen opened this issue · comments
Bhavesh Praveen commented
This is linked to issue python-poetry/poetry#2358
This is the existing code snippet of the validate()
in SelectChoiceValidator
present inclikit/ui/components/choice_question.py
if value < len(self._values):
result = self._values[value]
else:
result = False
So, if the user entered -3 as the input for a choice question, then it's still taken as a valid choice because Python supports negative indexing.
This might lead to inconsistencies.
Simple solution would be to modify the above condition to something like this
if 0 <= value < len(self._values):
result = self._values[value]
else:
result = False
Bhavesh Praveen commented
I've added a draft PR. Please let me know what you think.
Mathieu Kniewallner commented
Since #27 has been merged, it seems that this issue can be closed.