Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#721 closed defect (fixed)

isAlphaNumericURL validator should allow dashes.

Reported by: Esaj Owned by: adrian
Component: Validators Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.core.validators.isAlphaNumericURL should allow dashes. Dashes in URLs are apparently more search-engine friendly, and they don't do any harm.

Index: django/core/validators.py
===================================================================
--- django/core/validators.py   (revision 1066)
+++ django/core/validators.py   (working copy)
@@ -13,7 +13,7 @@
 _datere = r'\d{4}-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[12][0-9])|(?:3[0-1]))'
 _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?'
 alnum_re = re.compile(r'^\w+$')
-alnumurl_re = re.compile(r'^[\w/]+$')
+alnumurl_re = re.compile(r'^[-\w/]+$')
 ansi_date_re = re.compile('^%s$' % _datere)
 ansi_time_re = re.compile('^%s$' % _timere)
 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
@@ -58,7 +58,7 @@

 def isAlphaNumericURL(field_data, all_data):
     if not alnumurl_re.search(field_data):
-        raise ValidationError, "This value must contain only letters, numbers, underscores or slashes."
+        raise ValidationError, "This value must contain only letters, numbers, underscores, dashes or slashes."

 def isSlug(field_data, all_data):
     if not slug_re.search(field_data):

Attachments (1)

alnumurl.diff (1.0 KB) - added by Esaj 10 years ago.

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by Esaj

comment:1 Changed 10 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

A hyphen isn't an alphanumeric character, so it shouldn't be allowed in the isAlphaNumericURL validator. Feel free to write your own validator that takes care of hyphens.

comment:2 Changed 10 years ago by Esaj

  • Resolution wontfix deleted
  • Status changed from closed to reopened

It's true that it's not an alphanumeric character, but I think it's worth allowing hyphens in URLs for flatfiles. That's actually the only reason I opened this ticket, but I forgot to say it... oops!

comment:3 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [2353]) Fixed #721 -- isAlphaNumericURL validator now allows dashes

Note: See TracTickets for help on using tickets.
Back to Top