fields: don't crash on unkown CSS classes in profile fields (#29654)

This commit is contained in:
Frédéric Péters 2019-01-11 09:57:23 +01:00
parent 17e4fc2f30
commit b9d05a9aa4
2 changed files with 9 additions and 3 deletions

View File

@ -2124,7 +2124,10 @@ def test_form_page_profile_first_name_prefill(pub):
type='string', extra_css_class='autocomplete-given-name'),
fields.StringField(
id='_city', label='city',
type='string', extra_css_class='autocomplete-address-level2')
type='string', extra_css_class='autocomplete-address-level2'),
fields.StringField(
id='_plop', label='plop',
type='string', extra_css_class='xxx')
]
user_formdef.store()
user.form_data = {'_first_name': 'plop', '_city': 'mytown'}
@ -2139,7 +2142,10 @@ def test_form_page_profile_first_name_prefill(pub):
prefill={'type': 'user', 'value': '_first_name'}),
fields.StringField(
id='1', label='string',
prefill={'type': 'user', 'value': '_city'})
prefill={'type': 'user', 'value': '_city'}),
fields.StringField(
id='2', label='string',
prefill={'type': 'user', 'value': '_plop'}),
]
formdef.store()

View File

@ -381,7 +381,7 @@ class Field(object):
try:
autocomplete_attribute = re.search(r'\bautocomplete-([a-z0-9-]+)',
user_field.extra_css_class).groups()[0]
except (TypeError, IndexError):
except (TypeError, IndexError, AttributeError):
continue
return {'autocomplete': autocomplete_attribute}