RegexField should support unicode when use regex string #7756
Replies: 7 comments
-
Hi @layjump — Yes. Prima facie this is something we should handle.
If you want to open a PR adding your failing test case and making the change we can review and merge. Thanks for the report! |
Beta Was this translation helpful? Give feedback.
-
Hi @carltongibson Well If the flags are set, regex must be a regular expression string, Then a compiled regex won't be supported. |
Beta Was this translation helpful? Give feedback.
-
Ah, yes, of course. In that case I guess I'd rather check whether we should pass the flag... — it seems like otherwise we're pulling logic back out of Just a thought, has this come up on Django itself? Do they have a view on this? (i.e. Should Other than checking on Django, a PR with your test case is the right next step here. |
Beta Was this translation helpful? Give feedback.
-
Ah, well done 🙂 #5669 |
Beta Was this translation helpful? Give feedback.
-
Django's RegexField is as below:
It will compile using re.UNICODE when set_regex。 |
Beta Was this translation helpful? Give feedback.
-
Well,
It looks to me as if that should be doing something sensible with the So, first step is to see if that requirement on |
Beta Was this translation helpful? Give feedback.
-
Well, I think RegexValidator support this, but it was designed not support both pre-compile regex and flags the same time as the code shown. So they pre-compile regex with re.UNICODE flags and then pass it into RegexValidator in RegexField ( My PR do the same). |
Beta Was this translation helpful? Give feedback.
-
Checklist
I have verified that that issue exists against the
master
branch of Django REST framework.I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
Steps to reproduce
name = RegexField(r'^\w[\w.@+-]$')
Expected behavior
"你好" is a valid string
Actual behavior
"你好" is an invalid string and raise validate failed exception
code of RegexField in the 'master' branch is as below:
To support unicode, It should likely be:
Beta Was this translation helpful? Give feedback.
All reactions