#31311: Unneeded escape sequences in character classes
--------------------------------------+------------------------------------
     Reporter:  Kimball Leavitt       |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Core (Other)          |                  Version:  3.0
     Severity:  Normal                |               Resolution:
     Keywords:  validators, regex     |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):

 * has_patch:  1 => 0
 * stage:  Unreviewed => Accepted


Comment:

 The third example here (L162) is:

 {{{
 r'((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))\Z',
 }}}

 I can't see an escape inside a character class there.
 Might just be early?

 I applied a quick adjustment, which seemed to run OK. (Existing tests
 passed.)


 {{{
 diff --git a/django/core/validators.py b/django/core/validators.py
 index dc0519bb6a..c19fa0becd 100644
 --- a/django/core/validators.py
 +++ b/django/core/validators.py
 @@ -65,7 +65,7 @@ class URLValidator(RegexValidator):

      # IP patterns
      ipv4_re =
 r'(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
 -    ipv6_re = r'\[[0-9a-f:\.]+\]'  # (simple regex, validated later)
 +    ipv6_re = r'\[[0-9a-f:.]+\]'  # (simple regex, validated later)

      # Host patterns
      hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]{0,61}[a-z'
 + ul + r'0-9])?'
 @@ -82,7 +82,7 @@ class URLValidator(RegexValidator):
      host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)'

      regex = _lazy_re_compile(
 -        r'^(?:[a-z0-9\.\-\+]*)://'  # scheme is validated separately
 +        r'^(?:[a-z0-9.\-+]*)://'  # scheme is validated separately
          r'(?:[^\s:@/]+(?::[^\s:@/]*)?@)?'  # user:pass authentication
          r'(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')'
          r'(?::\d{2,5})?'  # port
 }}}

 Happy to look more closely in a PR.

 Thanks for the report.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31311#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.431c84eb0e730a988dc3c60583995339%40djangoproject.com.

Reply via email to