Skip to content

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

@bagerard

Description

@bagerard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions