Opened 19 years ago

Closed 19 years ago

Last modified 17 years ago

#721 closed defect (fixed)

isAlphaNumericURL validator should allow dashes.

Reported by: Esaj Owned by: Adrian Holovaty
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: no UI/UX: no

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 19 years ago.

Download all attachments as: .zip

Change History (4)

by Esaj, 19 years ago

Attachment: alnumurl.diff added

comment:1 by Adrian Holovaty, 19 years ago

Resolution: wontfix
Status: newclosed

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 by Esaj, 19 years ago

Resolution: wontfix
Status: closedreopened

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 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: reopenedclosed

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

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