Browse files

Merge pull request #101 from jphalip/tickets/18409-regexfield-unicode

Fixed #18409 -- Made RegexField work with unicode characters.
  • Loading branch information...
2 parents ba10be7 + f6fc83c commit 314d82a94e2d4270b6ec8aa4b3fc2e8ebc404f08 @jphalip jphalip committed May 31, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 django/forms/fields.py
  2. +8 −0 tests/regressiontests/forms/tests/fields.py
View
2 django/forms/fields.py
@@ -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)
View
8 tests/regressiontests/forms/tests/fields.py
@@ -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+$'

0 comments on commit 314d82a

Please sign in to comment.