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

Stripped out white space from email field #780

Closed
wants to merge 2 commits into from

Conversation

winninggodspower
Copy link

email field usually returns error when white space removed. Its fixed now

This request fixes the issue from this pull request: issue

email field usually returns error when white space removed. Its fixed now
@azmeuk
Copy link
Member

azmeuk commented Apr 4, 2023

You don't describe correctly what is the issue you intend to fix, your PR has no unit tests, and it breaks the other unit tests.

@winninggodspower
Copy link
Author

winninggodspower commented Apr 4, 2023

Sorry for that. I'm new to open source contribution.
While using the email field validation. It return invalid email when white space is attached to the email.
Eg "david@gmail.com "

But has no issues when the white space is removed. Eg "david@gmail.com".

What I did locally was to overing the call method in the Email class validator. Then remove the white space

class Email(Email):
    def __call__(self, form, field):
        field.data = field.data.strip()
        super()__call__(form, field)

It worked properly, locally. Then I decided to contribute.

Maybe you can help fixing it. Thanks!!

From the previous commit, error was raised because the field.data was of type NoneType

I'm making a check to see if the field data was passed before striping it
@azmeuk
Copy link
Member

azmeuk commented Jul 21, 2023

I think this is not needed. You should be able to achieve this with filters.

>>> import wtforms
>>> class F(wtforms.Form):
...     email = wtforms.EmailField(filters=[str.strip])
>>> f = F(email=" email@mydomain.tld ")
>>> f.email.data
'email@mydomain.tld'

Thank you anyways 🙇

Related to #793

@azmeuk azmeuk closed this Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants