sdispater / clikit

CliKit is a group of utilities to build beautiful and testable command line interfaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SelectChoiceValidator should probably disallow negative choices

bhaveshpraveen opened this issue · comments

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

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

Since #27 has been merged, it seems that this issue can be closed.