Files
notifications-admin/tests/app/main/test_strip_whitespace_form.py
Chris Hill-Scott 9e78c5f575 Strip obscure whitespace from form submissions
We strip most whitespace as of:
https://github.com/alphagov/notifications-admin/pull/1701

However we are still getting some bad email addresses through, for
example one that had a leading zero-width space character. This means
that the user sees a validation error; really we should just deal with
the mess for them.

So this commit also includes characters without Unicode character
property "WSpace=Y" (which includes zero-width space) to those which are
stripped from form submissions.

List taken from here: https://en.wikipedia.org/wiki/Whitespace_character

See issue and discussion here: https://bugs.python.org/issue13391
2018-04-25 16:12:24 +01:00

33 lines
662 B
Python

import pytest
from wtforms import Form, StringField
from app.main.forms import StripWhitespaceForm, StripWhitespaceStringField
class ExampleForm(StripWhitespaceForm):
foo = StringField('Foo')
class ExampleFormSpecialField(Form):
foo = StripWhitespaceStringField('foo')
@pytest.mark.parametrize('submitted_data', [
'bar',
' bar ',
"""
\t bar
""",
' \u180E\u200B \u200C bar \u200D \u2060\uFEFF ',
])
@pytest.mark.parametrize('form', [
ExampleForm,
ExampleFormSpecialField,
])
def test_form_strips_all_whitespace(
app_,
form,
submitted_data,
):
assert form(foo=submitted_data).foo.data == 'bar'