mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.5.x] Simplified smart_urlquote and added some basic tests.
Backport of b70c371fc1 from master.
This commit is contained in:
@@ -246,9 +246,10 @@ class DefaultFiltersTests(TestCase):
|
||||
'<a href="https://google.com" rel="nofollow">https://google.com</a>')
|
||||
|
||||
# Check urlize doesn't overquote already quoted urls - see #9655
|
||||
self.assertEqual(urlize('http://hi.baidu.com/%D6%D8%D0%C2%BF'),
|
||||
'<a href="http://hi.baidu.com/%D6%D8%D0%C2%BF" rel="nofollow">'
|
||||
'http://hi.baidu.com/%D6%D8%D0%C2%BF</a>')
|
||||
# The teststring is the urlquoted version of 'http://hi.baidu.com/重新开始'
|
||||
self.assertEqual(urlize('http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B'),
|
||||
'<a href="http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B" rel="nofollow">'
|
||||
'http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B</a>')
|
||||
self.assertEqual(urlize('www.mystore.com/30%OffCoupons!'),
|
||||
'<a href="http://www.mystore.com/30%25OffCoupons!" rel="nofollow">'
|
||||
'www.mystore.com/30%OffCoupons!</a>')
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
@@ -157,3 +158,13 @@ class TestUtilsHtml(unittest.TestCase):
|
||||
)
|
||||
for value, tags, output in items:
|
||||
self.assertEqual(f(value, tags), output)
|
||||
|
||||
def test_smart_urlquote(self):
|
||||
quote = html.smart_urlquote
|
||||
# Ensure that IDNs are properly quoted
|
||||
self.assertEqual(quote('http://öäü.com/'), 'http://xn--4ca9at.com/')
|
||||
self.assertEqual(quote('http://öäü.com/öäü/'), 'http://xn--4ca9at.com/%C3%B6%C3%A4%C3%BC/')
|
||||
# Ensure that everything unsafe is quoted, !*'();:@&=+$,/?#[]~ is considered safe as per RFC
|
||||
self.assertEqual(quote('http://example.com/path/öäü/'), 'http://example.com/path/%C3%B6%C3%A4%C3%BC/')
|
||||
self.assertEqual(quote('http://example.com/%C3%B6/ä/'), 'http://example.com/%C3%B6/%C3%A4/')
|
||||
self.assertEqual(quote('http://example.com/?x=1&y=2'), 'http://example.com/?x=1&y=2')
|
||||
|
||||
Reference in New Issue
Block a user