Skip to content

Commit dbd993d

Browse files
committed
wrapper for smart_urlquote, issue encode#1386
1 parent 08ec232 commit dbd993d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

rest_framework/templatetags/rest_framework.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ def add_class(value, css_class):
189189
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
190190

191191

192+
def smart_urlquote_wrapper(matched_url):
193+
"""
194+
Simple wrapper for smart_urlquote. ValueError("Invalid IPv6 URL") can
195+
be raised here, see issue #1386
196+
"""
197+
try:
198+
return smart_urlquote(matched_url)
199+
except ValueError:
200+
return None
201+
202+
192203
@register.filter
193204
def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True):
194205
"""
@@ -232,13 +243,9 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru
232243
url = None
233244
nofollow_attr = ' rel="nofollow"' if nofollow else ''
234245
if simple_url_re.match(middle):
235-
url = smart_urlquote(middle)
246+
url = smart_urlquote_wrapper(middle)
236247
elif simple_url_2_re.match(middle):
237-
# ValueError("Invalid IPv6 URL") can be raised here, see issue #1386
238-
try:
239-
url = smart_urlquote('http://%s' % middle)
240-
except ValueError:
241-
pass
248+
url = smart_urlquote_wrapper('http://%s' % middle)
242249
elif not ':' in middle and simple_email_re.match(middle):
243250
local, domain = middle.rsplit('@', 1)
244251
try:

0 commit comments

Comments
 (0)