mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-05 22:23:27 +03:00
wrapper for smart_urlquote, issue #1386
This commit is contained in:
parent
08ec23268d
commit
dbd993d108
|
@ -189,6 +189,17 @@ simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net
|
||||||
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
|
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
|
||||||
|
|
||||||
|
|
||||||
|
def smart_urlquote_wrapper(matched_url):
|
||||||
|
"""
|
||||||
|
Simple wrapper for smart_urlquote. ValueError("Invalid IPv6 URL") can
|
||||||
|
be raised here, see issue #1386
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return smart_urlquote(matched_url)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True):
|
def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True):
|
||||||
"""
|
"""
|
||||||
|
@ -232,13 +243,9 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru
|
||||||
url = None
|
url = None
|
||||||
nofollow_attr = ' rel="nofollow"' if nofollow else ''
|
nofollow_attr = ' rel="nofollow"' if nofollow else ''
|
||||||
if simple_url_re.match(middle):
|
if simple_url_re.match(middle):
|
||||||
url = smart_urlquote(middle)
|
url = smart_urlquote_wrapper(middle)
|
||||||
elif simple_url_2_re.match(middle):
|
elif simple_url_2_re.match(middle):
|
||||||
# ValueError("Invalid IPv6 URL") can be raised here, see issue #1386
|
url = smart_urlquote_wrapper('http://%s' % middle)
|
||||||
try:
|
|
||||||
url = smart_urlquote('http://%s' % middle)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
elif not ':' in middle and simple_email_re.match(middle):
|
elif not ':' in middle and simple_email_re.match(middle):
|
||||||
local, domain = middle.rsplit('@', 1)
|
local, domain = middle.rsplit('@', 1)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user