Skip to content

Commit

Permalink
Merge pull request django#101 from jphalip/tickets/18409-regexfield-u…
Browse files Browse the repository at this point in the history
…nicode

Fixed #18409 -- Made RegexField work with unicode characters.
  • Loading branch information
jphalip committed May 31, 2012
2 parents ba10be7 + f6fc83c commit 314d82a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def _get_regex(self):

def _set_regex(self, regex):
if isinstance(regex, basestring):
regex = re.compile(regex)
regex = re.compile(regex, re.UNICODE)
self._regex = regex
if hasattr(self, '_regex_validator') and self._regex_validator in self.validators:
self.validators.remove(self._regex_validator)
Expand Down
8 changes: 8 additions & 0 deletions tests/regressiontests/forms/tests/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,14 @@ def test_regexfield_5(self):
self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')

def test_regexfield_6(self):
"""
Ensure that it works with unicode characters.
Refs #.
"""
f = RegexField('^\w+$')
self.assertEqual(u'éèøçÎÎ你好', f.clean(u'éèøçÎÎ你好'))

def test_change_regex_after_init(self):
f = RegexField('^[a-z]+$')
f.regex = '^\d+$'
Expand Down

0 comments on commit 314d82a

Please sign in to comment.