When entering two backslashes into the URL validator it raises an `sre_constants.error`. As per the docs, it seems like the validator should catch this and then chain a `ValidationError` to the exception. This appears to be an issue with Django's integration with Python's regex implementation. This may just be my misunderstanding of the way Django handles validation, but it seems like any form of invalid input should raise a `ValidationError`.
I found this while running Django 1.6.2 on Python 3.3.0 on Windows 7.
This session reproduces the bug on my system.
>>> from django.core.validators import URLValidator
>>> URLValidator('\\')Traceback (most recent call last):
File "C:\Python33\lib\sre_parse.py", line 195, in __next
c = self.string[self.index + 1]
IndexError: string index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
File "C:\Python33\lib\site-packages\django\core\validators.py", line 32, in __init__
self.regex = re.compile(self.regex)
File "C:\Python33\lib\re.py", line 214, in compile
return _compile(pattern, flags)
File "C:\Python33\lib\functools.py", line 258, in wrapper
result = user_function(*args, **kwds)
File "C:\Python33\lib\re.py", line 274, in _compile
return sre_compile.compile(pattern, flags)
File "C:\Python33\lib\sre_compile.py", line 493, in compile
p = sre_parse.parse(p, flags)
File "C:\Python33\lib\sre_parse.py", line 717, in parse
source = Tokenizer(str)
File "C:\Python33\lib\sre_parse.py", line 183, in __init__
self.__next()
File "C:\Python33\lib\sre_parse.py", line 197, in __next
raise error("bogus escape (end of line)")
sre_constants.error: bogus escape (end of line)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b324829-5daf-4975-bc60-244dba0ded53%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment