From f6fc83c97514ced9de48ca9ea442a9b166d3e211 Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Thu, 31 May 2012 11:45:35 -0700 Subject: [PATCH] Fixed #18409 -- Made RegexField work with unicode characters. --- django/forms/fields.py | 2 +- tests/regressiontests/forms/tests/fields.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index 53250cc8a99..3811510326b 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -446,7 +446,7 @@ class RegexField(CharField): 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) diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index d66ee2c0848..c4a8a9a3fa2 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -478,6 +478,14 @@ class FieldsTests(SimpleTestCase): 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+$'