magmax/python-inquirer

Regex validation in inquirer.Text not working

Closed this issue · 1 comments

Greetings,
There is an issue with the validation of input in inquirer.Text. It is throwing the error below even though the string is following the regex pattern.

[token] is not a valid token.

To replicate:

  • run test.py containing the following:
import inquirer
import re

questions = [
    inquirer.Text('token', message="Token",
                  validate=lambda _, x: re.match("(\S{24})([.])(\S{6})([.])(\S{27})", x),
                  )
]
token = inquirer.prompt(questions)
print(token)
  • input the following string:
ODUwNjM5NTc4NzE2ODMxNzY0.YLsp1w.xrRuEEU_316438lrWpNrm2lmv9Y

or anything that follows this regex pattern "(\S{24})([.])(\S{6})([.])(\S{27})"

  • the terminal should throw the following error:
>> "ODUwNjM5NTc4NzE2ODMxNzY0.YLsp1w.xrRuEEU_316438lrWp" is not a valid token. 

I tested the string to see if it really triggers the match using the code below and it did.

import re

str = "ODUwNjM5NTc4NzE2ODMxNzY0.YLsp1w.xrRuEEU_316438lrWpNrm2lmv9Y"
r = re.match("(\S{24})([.])(\S{6})([.])(\S{27})$", str)
print(str[:r.span()[1]] == str)

However, further testing shows that if i used "(\S{24})([.])(\S{6})([.])(\S)" as the regex pattern instead of "(\S{24})([.])(\S{6})([.])(\S{27})", it matches.

Notes:

OS: Linux
python-inquirer version: 2.7.0

Thank you and good day!

I'm afraid the regexp matches that string, so it is a valid one.