Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email validator fails unexpectedly if we give it anything else than a string #141

Open
bagerard opened this issue Aug 20, 2018 · 1 comment

Comments

@bagerard
Copy link
Contributor

Hi, while challenging our API with random input we noticed that the Email validator wasn't failing with a ValidationError when we give it the wrong input:

em = fe.validators.Email()
em.to_python(45)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-4dfaedfd72a0> in <module>()
----> 1 em.to_python(45)

~/.pyenv/versions/3.6.5/envs/cmp/lib/python3.6/site-packages/formencode/api.py in to_python(self, value, state)
--> 475                 value = tp(value, state)
~/.pyenv/versions/3.6.5/envs/cmp/lib/python3.6/site-packages/formencode/validators.py in _convert_to_python(self, value, state)
-> 1390         return value.strip()

AttributeError: 'int' object has no attribute 'strip'

Before starting to work on this, I was wondering if there is any reason that validators.Email inherit from FancyValidator and not from validators.String? In fact, changing this would fix this bug

@NucleaPeon
Copy link

You might try putting it into an All() validator in the meantime. I had to put email first, then unicodestring (All() seems to run from the last validator to the first?)

allem = All(Email(), UnicodeString())
>>> allem.to_python(45)

Then you will get a traceback:

Traceback (most recent call last):
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/validators.py", line 1347, in _validate_python
    username, domain = splitted
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/api.py", line 475, in to_python
    value = tp(value, state)
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/compound.py", line 65, in _convert_to_python
    to_python)
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/compound.py", line 175, in _attempt_convert
    value = validate(validator, value, state)
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/compound.py", line 16, in to_python
    return validator.to_python(value, state)
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/api.py", line 478, in to_python
    vp(value, state)
File "/home/vagrant/meso_venv/lib/python3.7/site-packages/formencode/validators.py", line 1349, in _validate_python
    raise Invalid(self.message('noAt', state), value, state)
formencode.api.Invalid: An email address must contain a single @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants