sdispater / clikit

CliKit is a group of utilities to build beautiful and testable command line interfaces.
MIT License
72 stars 17 forks source link

SelectChoiceValidator should probably disallow negative choices #26

Open bhaveshpraveen opened 4 years ago

bhaveshpraveen commented 4 years ago

This is linked to issue https://github.com/python-poetry/poetry/issues/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
bhaveshpraveen commented 4 years ago

I've added a draft PR. Please let me know what you think.

mkniewallner commented 2 years ago

Since https://github.com/sdispater/clikit/pull/27 has been merged, it seems that this issue can be closed.