Skip to content

Commit

Permalink
Fix email extractor. Must not raise ExtractionError if not required o…
Browse files Browse the repository at this point in the history
…n empty input.
  • Loading branch information
rnixx committed Apr 11, 2015
1 parent 41a1038 commit 9ad0fd7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
History
=======

2.1.3 (unreleased)
------------------

- Fix email extractor. Must not raise ExtractionError if not required on empty
input.
[rnix, 2015-04-11]


2.1.2 (2015-01-23)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)


version = '2.1.2'
version = '2.1.3.dev0'
shortdesc = \
'YAFOWIL - declarative, flexible html forms, framework independent.'
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Expand Down
4 changes: 3 additions & 1 deletion src/yafowil/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,9 @@ def submit_renderer(widget, data):

def email_extractor(widget, data):
val = data.extracted
if not re.match(EMAIL_RE, val is not UNSET and val or ''):
if not val:
return val
if not re.match(EMAIL_RE, val):
message = _('email_address_not_valid',
default=u'Input not a valid email address.')
raise ExtractionError(message)
Expand Down
19 changes: 18 additions & 1 deletion src/yafowil/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ Render empty (WHAT'S THIS GOOD FOR?)::
<BLANKLINE>


e-mail
E-Mail
------

::
Expand All @@ -2310,6 +2310,10 @@ e-mail
>>> pxml(widget())
<input class="email" id="input-email" name="email" type="email" value=""/>

>>> data = widget.extract({'email': ''})
>>> data.errors
[]

>>> data = widget.extract({'email': 'foo@bar'})
>>> data.errors
[ExtractionError('Input not a valid email address.',)]
Expand All @@ -2322,6 +2326,19 @@ e-mail
>>> data.errors
[]

>>> widget = factory(
... 'email',
... name='email',
... props={'required': 'E-Mail Address is required'})

>>> data = widget.extract({'email': ''})
>>> data.errors
[ExtractionError('E-Mail Address is required',)]

>>> data = widget.extract({'email': 'foo@bar.com'})
>>> data.errors
[]


URL
---
Expand Down

0 comments on commit 9ad0fd7

Please sign in to comment.