Ticket #16028: 16028.WIP.diff
File 16028.WIP.diff, 32.5 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/defaultfilters/tests.py
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index cbd4776..08afd4d 100644
a b from django.template.defaultfilters import * 9 9 class DefaultFiltersTests(TestCase): 10 10 11 11 def test_floatformat(self): 12 self.assertEqual(floatformat(7.7), u'7.7')13 self.assertEqual(floatformat(7.0), u'7')14 self.assertEqual(floatformat(0.7), u'0.7')15 self.assertEqual(floatformat(0.07), u'0.1')16 self.assertEqual(floatformat(0.007), u'0.0')17 self.assertEqual(floatformat(0.0), u'0')18 self.assertEqual(floatformat(7.7, 3), u'7.700')19 self.assertEqual(floatformat(6.000000, 3), u'6.000')20 self.assertEqual(floatformat(6.200000, 3), u'6.200')21 self.assertEqual(floatformat(6.200000, -3), u'6.200')22 self.assertEqual(floatformat(13.1031, -3), u'13.103')23 self.assertEqual(floatformat(11.1197, -2), u'11.12')24 self.assertEqual(floatformat(11.0000, -2), u'11')25 self.assertEqual(floatformat(11.000001, -2), u'11.00')26 self.assertEqual(floatformat(8.2798, 3), u'8.280')27 self.assertEqual(floatformat(u'foo'), u'')28 self.assertEqual(floatformat(13.1031, u'bar'), u'13.1031')29 self.assertEqual(floatformat(18.125, 2), u'18.13')30 self.assertEqual(floatformat(u'foo', u'bar'), u'')31 self.assertEqual(floatformat(u'¿Cómo esta usted?'), u'')32 self.assertEqual(floatformat(None), u'')33 34 # Check that we're not converting to scientific notation.35 self.assertEqual(floatformat(0, 6), u'0.000000')36 self.assertEqual(floatformat(0, 7), u'0.0000000')37 self.assertEqual(floatformat(0, 10), u'0.0000000000')38 self.assertEqual(floatformat(0.000000000000000000015, 20),39 u'0.00000000000000000002')40 41 12 pos_inf = float(1e30000) 42 13 self.assertEqual(floatformat(pos_inf), unicode(pos_inf)) 43 14 … … class DefaultFiltersTests(TestCase): 62 33 def test_floatformat_fail(self): 63 34 self.assertEqual(floatformat(1.00000000000000015, 16), u'1.0000000000000002') 64 35 65 def test_addslashes(self):66 self.assertEqual(addslashes(u'"double quotes" and \'single quotes\''),67 u'\\"double quotes\\" and \\\'single quotes\\\'')68 69 self.assertEqual(addslashes(ur'\ : backslashes, too'),70 u'\\\\ : backslashes, too')71 72 def test_capfirst(self):73 self.assertEqual(capfirst(u'hello world'), u'Hello world')74 75 def test_escapejs(self):76 self.assertEqual(escapejs(u'"double quotes" and \'single quotes\''),77 u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027')78 self.assertEqual(escapejs(ur'\ : backslashes, too'),79 u'\\u005C : backslashes, too')80 self.assertEqual(escapejs(u'and lots of whitespace: \r\n\t\v\f\b'),81 u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008')82 self.assertEqual(escapejs(ur'<script>and this</script>'),83 u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E')84 self.assertEqual(85 escapejs(u'paragraph separator:\u2029and line separator:\u2028'),86 u'paragraph separator:\\u2029and line separator:\\u2028')87 88 def test_fix_ampersands(self):89 self.assertEqual(fix_ampersands(u'Jack & Jill & Jeroboam'),90 u'Jack & Jill & Jeroboam')91 92 def test_linenumbers(self):93 self.assertEqual(linenumbers(u'line 1\nline 2'),94 u'1. line 1\n2. line 2')95 self.assertEqual(linenumbers(u'\n'.join([u'x'] * 10)),96 u'01. x\n02. x\n03. x\n04. x\n05. x\n06. x\n07. '\97 u'x\n08. x\n09. x\n10. x')98 99 def test_lower(self):100 self.assertEqual(lower('TEST'), u'test')101 102 # uppercase E umlaut103 self.assertEqual(lower(u'\xcb'), u'\xeb')104 105 def test_make_list(self):106 self.assertEqual(make_list('abc'), [u'a', u'b', u'c'])107 self.assertEqual(make_list(1234), [u'1', u'2', u'3', u'4'])108 109 def test_slugify(self):110 self.assertEqual(slugify(' Jack & Jill like numbers 1,2,3 and 4 and'\111 ' silly characters ?%.$!/'),112 u'jack-jill-like-numbers-123-and-4-and-silly-characters')113 114 self.assertEqual(slugify(u"Un \xe9l\xe9phant \xe0 l'or\xe9e du bois"),115 u'un-elephant-a-loree-du-bois')116 117 def test_stringformat(self):118 self.assertEqual(stringformat(1, u'03d'), u'001')119 self.assertEqual(stringformat(1, u'z'), u'')120 121 def test_title(self):122 self.assertEqual(title('a nice title, isn\'t it?'),123 u"A Nice Title, Isn't It?")124 self.assertEqual(title(u'discoth\xe8que'), u'Discoth\xe8que')125 126 def test_truncatewords(self):127 self.assertEqual(128 truncatewords(u'A sentence with a few words in it', 1), u'A ...')129 self.assertEqual(130 truncatewords(u'A sentence with a few words in it', 5),131 u'A sentence with a few ...')132 self.assertEqual(133 truncatewords(u'A sentence with a few words in it', 100),134 u'A sentence with a few words in it')135 self.assertEqual(136 truncatewords(u'A sentence with a few words in it',137 'not a number'), u'A sentence with a few words in it')138 139 def test_truncatewords_html(self):140 self.assertEqual(truncatewords_html(141 u'<p>one <a href="#">two - three <br>four</a> five</p>', 0), u'')142 self.assertEqual(truncatewords_html(u'<p>one <a href="#">two - '\143 u'three <br>four</a> five</p>', 2),144 u'<p>one <a href="#">two ...</a></p>')145 self.assertEqual(truncatewords_html(146 u'<p>one <a href="#">two - three <br>four</a> five</p>', 4),147 u'<p>one <a href="#">two - three <br>four ...</a></p>')148 self.assertEqual(truncatewords_html(149 u'<p>one <a href="#">two - three <br>four</a> five</p>', 5),150 u'<p>one <a href="#">two - three <br>four</a> five</p>')151 self.assertEqual(truncatewords_html(152 u'<p>one <a href="#">two - three <br>four</a> five</p>', 100),153 u'<p>one <a href="#">two - three <br>four</a> five</p>')154 self.assertEqual(truncatewords_html(155 u'\xc5ngstr\xf6m was here', 1), u'\xc5ngstr\xf6m ...')156 157 def test_upper(self):158 self.assertEqual(upper(u'Mixed case input'), u'MIXED CASE INPUT')159 # lowercase e umlaut160 self.assertEqual(upper(u'\xeb'), u'\xcb')161 162 def test_urlencode(self):163 self.assertEqual(urlencode(u'fran\xe7ois & jill'),164 u'fran%C3%A7ois%20%26%20jill')165 self.assertEqual(urlencode(1), u'1')166 167 def test_iriencode(self):168 self.assertEqual(iriencode(u'S\xf8r-Tr\xf8ndelag'),169 u'S%C3%B8r-Tr%C3%B8ndelag')170 self.assertEqual(iriencode(urlencode(u'fran\xe7ois & jill')),171 u'fran%C3%A7ois%20%26%20jill')172 173 def test_urlizetrunc(self):174 self.assertEqual(urlizetrunc(u'http://short.com/', 20), u'<a href='\175 u'"http://short.com/" rel="nofollow">http://short.com/</a>')176 177 self.assertEqual(urlizetrunc(u'http://www.google.co.uk/search?hl=en'\178 u'&q=some+long+url&btnG=Search&meta=', 20), u'<a href="http://'\179 u'www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&'\180 u'meta=" rel="nofollow">http://www.google...</a>')181 182 self.assertEqual(urlizetrunc('http://www.google.co.uk/search?hl=en'\183 u'&q=some+long+url&btnG=Search&meta=', 20), u'<a href="http://'\184 u'www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search'\185 u'&meta=" rel="nofollow">http://www.google...</a>')186 187 # Check truncating of URIs which are the exact length188 uri = 'http://31characteruri.com/test/'189 self.assertEqual(len(uri), 31)190 191 self.assertEqual(urlizetrunc(uri, 31),192 u'<a href="http://31characteruri.com/test/" rel="nofollow">'\193 u'http://31characteruri.com/test/</a>')194 195 self.assertEqual(urlizetrunc(uri, 30),196 u'<a href="http://31characteruri.com/test/" rel="nofollow">'\197 u'http://31characteruri.com/t...</a>')198 199 self.assertEqual(urlizetrunc(uri, 2),200 u'<a href="http://31characteruri.com/test/"'\201 u' rel="nofollow">...</a>')202 203 def test_urlize(self):204 # Check normal urlize205 self.assertEqual(urlize('http://google.com'),206 u'<a href="http://google.com" rel="nofollow">http://google.com</a>')207 self.assertEqual(urlize('http://google.com/'),208 u'<a href="http://google.com/" rel="nofollow">http://google.com/</a>')209 self.assertEqual(urlize('www.google.com'),210 u'<a href="http://www.google.com" rel="nofollow">www.google.com</a>')211 self.assertEqual(urlize('djangoproject.org'),212 u'<a href="http://djangoproject.org" rel="nofollow">djangoproject.org</a>')213 self.assertEqual(urlize('info@djangoproject.org'),214 u'<a href="mailto:info@djangoproject.org">info@djangoproject.org</a>')215 216 # Check urlize with https addresses217 self.assertEqual(urlize('https://google.com'),218 u'<a href="https://google.com" rel="nofollow">https://google.com</a>')219 220 def test_wordcount(self):221 self.assertEqual(wordcount(''), 0)222 self.assertEqual(wordcount(u'oneword'), 1)223 self.assertEqual(wordcount(u'lots of words'), 3)224 225 self.assertEqual(wordwrap(u'this is a long paragraph of text that '\226 u'really needs to be wrapped I\'m afraid', 14),227 u"this is a long\nparagraph of\ntext that\nreally needs\nto be "\228 u"wrapped\nI'm afraid")229 230 self.assertEqual(wordwrap(u'this is a short paragraph of text.\n '\231 u'But this line should be indented', 14),232 u'this is a\nshort\nparagraph of\ntext.\n But this\nline '\233 u'should be\nindented')234 235 self.assertEqual(wordwrap(u'this is a short paragraph of text.\n '\236 u'But this line should be indented',15), u'this is a short\n'\237 u'paragraph of\ntext.\n But this line\nshould be\nindented')238 239 36 def test_rjust(self): 240 37 self.assertEqual(ljust(u'test', 10), u'test ') 241 38 self.assertEqual(ljust(u'test', 3), u'test') -
tests/regressiontests/templates/filters.py
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index 65f98e9..caa5a44 100644
a b def get_filter_tests(): 86 86 87 87 'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"<a>\' <a>\'"), 88 88 'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"<a>\' <a>\'"), 89 'filter-addslash03': ("{{ a|addslashes }}", {"a": mark_safe(u"\"double quotes\" and 'single quotes'")}, u"\\\"double quotes\\\" and \\'single quotes\\'"), 90 'filter-addslash04': ("{{ a|addslashes }}", {"a": mark_safe(ur"\ : backslashes, too")}, u"\\\\ : backslashes, too"), 89 91 90 92 'filter-capfirst01': ("{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}", {"a": "fred>", "b": mark_safe("fred>")}, u"Fred> Fred>"), 91 93 'filter-capfirst02': ("{{ a|capfirst }} {{ b|capfirst }}", {"a": "fred>", "b": mark_safe("fred>")}, u"Fred> Fred>"), 94 'filter-capfirst03': ("{{ a|capfirst }}", {"a": "hello world"}, u"Hello world"), 92 95 93 96 # Note that applying fix_ampsersands in autoescape mode leads to 94 97 # double escaping. 95 98 'filter-fix_ampersands01': ("{% autoescape off %}{{ a|fix_ampersands }} {{ b|fix_ampersands }}{% endautoescape %}", {"a": "a&b", "b": mark_safe("a&b")}, u"a&b a&b"), 96 99 'filter-fix_ampersands02': ("{{ a|fix_ampersands }} {{ b|fix_ampersands }}", {"a": "a&b", "b": mark_safe("a&b")}, u"a&amp;b a&b"), 100 'filter-fix_ampersands03': ("{{ a|fix_ampersands }}", {"a": mark_safe(u"Jack & Jill & Jeroboam")}, u"Jack & Jill & Jeroboam"), 97 101 98 102 'filter-floatformat01': ("{% autoescape off %}{{ a|floatformat }} {{ b|floatformat }}{% endautoescape %}", {"a": "1.42", "b": mark_safe("1.42")}, u"1.4 1.4"), 99 103 'filter-floatformat02': ("{{ a|floatformat }} {{ b|floatformat }}", {"a": "1.42", "b": mark_safe("1.42")}, u"1.4 1.4"), 104 'filter-floatformat03': ("{{ a|floatformat }}", {"a": 7.7}, u"7.7"), 105 'filter-floatformat04': ("{{ a|floatformat }}", {"a": 7.0}, u"7"), 106 'filter-floatformat05': ("{{ a|floatformat }}", {"a": 0.7}, u"0.7"), 107 'filter-floatformat06': ("{{ a|floatformat }}", {"a": 0.07}, u"0.1"), 108 'filter-floatformat07': ("{{ a|floatformat }}", {"a": 0.007}, u"0.0"), 109 'filter-floatformat08': ("{{ a|floatformat }}", {"a": 0.0}, u"0"), 110 'filter-floatformat09': ("{{ a|floatformat:b }}", {"a": 7.7, "b": "3"}, u"7.700"), 111 'filter-floatformat10': ("{{ a|floatformat:b }}", {"a": 6.000000, "b": 3}, u"6.000"), 112 'filter-floatformat11': ("{{ a|floatformat:b }}", {"a": 6.200000, "b": 3}, u"6.200"), 113 'filter-floatformat12': ("{{ a|floatformat:b }}", {"a": 6.200000, "b": -3}, u"6.200"), 114 'filter-floatformat13': ("{{ a|floatformat:b }}", {"a": 13.1031, "b": -3}, u"13.103"), 115 'filter-floatformat14': ("{{ a|floatformat:b }}", {"a": 11.1197, "b": -2}, u"11.12"), 116 'filter-floatformat15': ("{{ a|floatformat:b }}", {"a": 11.0000, "b": -2}, u"11"), 117 'filter-floatformat16': ("{{ a|floatformat:b }}", {"a": 11.000001, "b": -2}, u"11.00"), 118 'filter-floatformat17': ("{{ a|floatformat:b }}", {"a": 8.2798, "b": 3}, u"8.280"), 119 'filter-floatformat18': ("{{ a|floatformat }}", {"a": "foo"}, u""), 120 'filter-floatformat19': ("{{ a|floatformat:b }}", {"a": 13.1031, "b": "bar"}, u"13.1031"), 121 'filter-floatformat20': ("{{ a|floatformat:b }}", {"a": 18.125, "b": 2}, u"18.13"), 122 'filter-floatformat21': ("{{ a|floatformat:b }}", {"a": "foo", "b": "bar"}, u""), 123 'filter-floatformat22': ("{{ a|floatformat }}", {"a": "¿Cómo esta usted?"}, u""), 124 'filter-floatformat23': ("{{ a|floatformat }}", {"a": None}, u""), 125 126 # Check that we're not converting to scientific notation. 127 'filter-floatformat24': ("{{ a|floatformat:b }}", {"a": 0, "b": 6}, u"0.000000"), 128 'filter-floatformat25': ("{{ a|floatformat:b }}", {"a": 0, "b": 7}, u"0.0000000"), 129 'filter-floatformat26': ("{{ a|floatformat:b }}", {"a": 0, "b": 10}, u"0.0000000000"), 130 'filter-floatformat27': ("{{ a|floatformat:b }}", {"a": 0.000000000000000000015, "b": 20}, u"0.00000000000000000002"), 100 131 101 132 # The contents of "linenumbers" is escaped according to the current 102 133 # autoescape setting. 103 134 'filter-linenumbers01': ("{{ a|linenumbers }} {{ b|linenumbers }}", {"a": "one\n<two>\nthree", "b": mark_safe("one\n<two>\nthree")}, u"1. one\n2. <two>\n3. three 1. one\n2. <two>\n3. three"), 104 135 'filter-linenumbers02': ("{% autoescape off %}{{ a|linenumbers }} {{ b|linenumbers }}{% endautoescape %}", {"a": "one\n<two>\nthree", "b": mark_safe("one\n<two>\nthree")}, u"1. one\n2. <two>\n3. three 1. one\n2. <two>\n3. three"), 136 'filter-linenumbers03': ("{{ a|linenumbers }}", {"a": "line 1\nline 2"}, u"1. line 1\n2. line 2"), 137 'filter-linenumbers04': ("{{ a|linenumbers }}", {"a": "\n".join([u'x'] * 10)}, u"01. x\n02. x\n03. x\n04. x\n05. x\n06. x\n07. x\n08. x\n09. x\n10. x"), 105 138 106 139 'filter-lower01': ("{% autoescape off %}{{ a|lower }} {{ b|lower }}{% endautoescape %}", {"a": "Apple & banana", "b": mark_safe("Apple & banana")}, u"apple & banana apple & banana"), 107 140 'filter-lower02': ("{{ a|lower }} {{ b|lower }}", {"a": "Apple & banana", "b": mark_safe("Apple & banana")}, u"apple & banana apple & banana"), 141 'filter-lower03': ("{{ a|lower }}", {"a": "TEST"}, u"test"), 142 'filter-lower04': ("{{ a|lower }}", {"a": u"\xcb"}, u"\xeb"), # uppercase E umlaut 108 143 109 144 # The make_list filter can destroy existing escaping, so the results are 110 145 # escaped. … … def get_filter_tests(): 112 147 'filter-make_list02': ("{{ a|make_list }}", {"a": mark_safe("&")}, u"[u'&']"), 113 148 'filter-make_list03': ('{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}', {"a": mark_safe("&")}, u"[u'&']"), 114 149 'filter-make_list04': ('{{ a|make_list|stringformat:"s"|safe }}', {"a": mark_safe("&")}, u"[u'&']"), 150 'filter-make_list05': ('{% autoescape off %}{{ a|make_list }}{% endautoescape %}', {"a": 'abc'}, u"[u'a', u'b', u'c']"), 151 'filter-make_list06': ('{% autoescape off %}{{ a|make_list }}{% endautoescape %}', {"a": 1234}, u"[u'1', u'2', u'3', u'4']"), 115 152 116 153 # Running slugify on a pre-escaped string leads to odd behaviour, 117 154 # but the result is still safe. 118 155 'filter-slugify01': ("{% autoescape off %}{{ a|slugify }} {{ b|slugify }}{% endautoescape %}", {"a": "a & b", "b": mark_safe("a & b")}, u"a-b a-amp-b"), 119 156 'filter-slugify02': ("{{ a|slugify }} {{ b|slugify }}", {"a": "a & b", "b": mark_safe("a & b")}, u"a-b a-amp-b"), 157 'filter-slugify03': ("{{ a|slugify }}", {"a": " Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/"}, u"jack-jill-like-numbers-123-and-4-and-silly-characters"), 158 'filter-slugify04': ("{{ a|slugify }}", {"a": u"Un \xe9l\xe9phant \xe0 l'or\xe9e du bois"}, u"un-elephant-a-loree-du-bois"), 120 159 121 160 # Notice that escaping is applied *after* any filters, so the string 122 161 # formatting here only needs to deal with pre-escaped characters. … … def get_filter_tests(): 124 163 {"a": "a<b", "b": mark_safe("a<b")}, u". a<b. . a<b."), 125 164 'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, 126 165 u". a<b. . a<b."), 166 'filter-stringformat03': ('{{ a|stringformat:"03d" }}', {'a': 1}, u'001'), 167 'filter-stringformat04': ('{{ a|stringformat:"z" }}', {'a': 1}, u''), 127 168 128 169 # Test the title filter 129 'filter-title1' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, u'Joe's Crab Shack'), 130 'filter-title2' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, u'555 West 53rd Street'), 170 'filter-title01' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, u'Joe's Crab Shack'), 171 'filter-title02' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, u'555 West 53rd Street'), 172 'filter-title03' : ('{% autoescape off %}{{ a|title }}{% endautoescape %}', {'a' : 'a nice title, isn\'t it?'}, u'A Nice Title, Isn\'t It?'), 173 'filter-title04' : ('{{ a|title }}', {'a' : u'discoth\xe8que'}, u'Discoth\xe8que'), 131 174 132 175 'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', 133 176 {"a": "alpha & bravo", "b": mark_safe("alpha & bravo")}, u"alpha & ... alpha & ..."), 134 177 'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', 135 178 {"a": "alpha & bravo", "b": mark_safe("alpha & bravo")}, u"alpha & ... alpha & ..."), 179 'filter-truncatewords03': ('{{ a|truncatewords:b }}', 180 {"a": "A sentence with a few words in it", "b": 1}, u"A ..."), 181 'filter-truncatewords04': ('{{ a|truncatewords:b }}', 182 {"a": "A sentence with a few words in it", "b": 5}, u"A sentence with a few ..."), 183 'filter-truncatewords05': ('{{ a|truncatewords:b }}', 184 {"a": "A sentence with a few words in it", "b": 100}, u"A sentence with a few words in it"), 185 'filter-truncatewords06': ('{{ a|truncatewords:b }}', 186 {"a": "A sentence with a few words in it", "b": "not a number"}, u"A sentence with a few words in it"), 187 188 'filter-truncatewords_html01': ('{{ a|truncatewords_html:b }}', {'a': mark_safe('<p>one <a href="#">two - three <br>four</a> five</p>'), 'b': 0}, u''), 189 'filter-truncatewords_html02': ('{{ a|truncatewords_html:b }}', {'a': mark_safe('<p>one <a href="#">two - three <br>four</a> five</p>'), 'b': 2}, u'<p>one <a href="#">two ...</a></p>'), 190 'filter-truncatewords_html03': ('{{ a|truncatewords_html:b }}', {'a': mark_safe('<p>one <a href="#">two - three <br>four</a> five</p>'), 'b': 4}, u'<p>one <a href="#">two - three <br>four ...</a></p>'), 191 'filter-truncatewords_html04': ('{{ a|truncatewords_html:b }}', {'a': mark_safe('<p>one <a href="#">two - three <br>four</a> five</p>'), 'b': 5}, u'<p>one <a href="#">two - three <br>four</a> five</p>'), 192 'filter-truncatewords_html05': ('{{ a|truncatewords_html:b }}', {'a': mark_safe('<p>one <a href="#">two - three <br>four</a> five</p>'), 'b': 100}, u'<p>one <a href="#">two - three <br>four</a> five</p>'), 193 'filter-truncatewords_html06': ('{{ a|truncatewords_html:b }}', {'a': u'\xc5ngstr\xf6m was here', 'b': 1}, u'\xc5ngstr\xf6m ...'), 136 194 137 195 'filter-truncatechars01': ('{{ a|truncatechars:5 }}', {'a': "Testing, testing"}, u"Te..."), 138 196 'filter-truncatechars02': ('{{ a|truncatechars:7 }}', {'a': "Testing"}, u"Testing"), … … def get_filter_tests(): 141 199 # so it's not safe for non-escaping purposes. 142 200 'filter-upper01': ('{% autoescape off %}{{ a|upper }} {{ b|upper }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, u"A & B A & B"), 143 201 'filter-upper02': ('{{ a|upper }} {{ b|upper }}', {"a": "a & b", "b": mark_safe("a & b")}, u"A & B A &AMP; B"), 202 'filter-upper03': ('{{ a|upper }}', {"a": "Mixed case input"}, u"MIXED CASE INPUT"), 203 'filter-upper04': ('{{ a|upper }}', {"a": u"\xeb"}, u"\xcb"), 144 204 145 205 'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/?x=&y=" rel="nofollow">http://example.com/?x=&y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'), 146 206 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/?x=&y=" rel="nofollow">http://example.com/?x=&y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'), … … def get_filter_tests(): 156 216 'filter-urlize07': ('{{ a|urlize }}', {"a": "Email me at me@example.com"}, 'Email me at <a href="mailto:me@example.com">me@example.com</a>'), 157 217 'filter-urlize08': ('{{ a|urlize }}', {"a": "Email me at <me@example.com>"}, 'Email me at <<a href="mailto:me@example.com">me@example.com</a>>'), 158 218 219 'filter-urlize09': ('{{ a|urlize }}', {'a': 'http://google.com'}, u'<a href="http://google.com" rel="nofollow">http://google.com</a>'), 220 'filter-urlize10': ('{{ a|urlize }}', {'a': 'http://google.com/'}, u'<a href="http://google.com/" rel="nofollow">http://google.com/</a>'), 221 'filter-urlize11': ('{{ a|urlize }}', {'a': 'www.google.com'}, u'<a href="http://www.google.com" rel="nofollow">www.google.com</a>'), 222 'filter-urlize12': ('{{ a|urlize }}', {'a': 'djangoproject.org'}, u'<a href="http://djangoproject.org" rel="nofollow">djangoproject.org</a>'), 223 'filter-urlize13': ('{{ a|urlize }}', {'a': 'info@djangoproject.org'}, u'<a href="mailto:info@djangoproject.org">info@djangoproject.org</a>'), 224 225 # Check urlize with https addresses 226 'filter-urlize10': ('{{ a|urlize }}', {'a': 'https://google.com'}, u'<a href="https://google.com" rel="nofollow">https://google.com</a>'), 227 228 159 229 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), 160 230 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), 231 'filter-urlizetrunc03': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://short.com/', 'b': 20}, u'<a href="http://short.com/" rel="nofollow">http://short.com/</a>'), 232 'filter-urlizetrunc04': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 'b': 20}, u'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google...</a>'), 233 'filter-urlizetrunc05': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 'b': 20}, u'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google...</a>'), 234 # Check truncating of URIs which are the exact length 235 'filter-urlizetrunc06': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://31characteruri.com/test/', 'b': 31}, u'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/test/</a>'), 236 'filter-urlizetrunc07': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://31characteruri.com/test/', 'b': 30}, u'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/t...</a>'), 237 'filter-urlizetrunc08': ('{% autoescape off %}{{ a|urlizetrunc:b }}{% endautoescape %}', {'a': 'http://31characteruri.com/test/', 'b': 2}, u'<a href="http://31characteruri.com/test/" rel="nofollow">...</a>'), 161 238 162 239 'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), 163 240 'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), 241 'filter-wordcount03': ('{{ a|wordcount }}', {"a": ""}, u"0"), 242 'filter-wordcount04': ('{{ a|wordcount }}', {"a": "oneword"}, u"1"), 243 'filter-wordcount05': ('{{ a|wordcount }}', {"a": "lots of words"}, u"3"), 164 244 165 245 'filter-wordwrap01': ('{% autoescape off %}{{ a|wordwrap:"3" }} {{ b|wordwrap:"3" }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, u"a &\nb a &\nb"), 166 246 'filter-wordwrap02': ('{{ a|wordwrap:"3" }} {{ b|wordwrap:"3" }}', {"a": "a & b", "b": mark_safe("a & b")}, u"a &\nb a &\nb"), 247 'filter-wordwrap03': ('{{ a|wordwrap:b }}', {"a": mark_safe("this is a long paragraph of text that really needs to be wrapped I\'m afraid"), "b": 14}, u"this is a long\nparagraph of\ntext that\nreally needs\nto be wrapped\nI'm afraid"), 248 'filter-wordwrap04': ('{{ a|wordwrap:b }}', {"a": "this is a short paragraph of text.\n But this line should be indented", "b": 14}, u"this is a\nshort\nparagraph of\ntext.\n But this\nline should be\nindented"), 249 'filter-wordwrap05': ('{{ a|wordwrap:b }}', {"a": "this is a short paragraph of text.\n But this line should be indented", "b": 15}, u"this is a short\nparagraph of\ntext.\n But this line\nshould be\nindented"), 167 250 168 251 'filter-ljust01': ('{% autoescape off %}.{{ a|ljust:"5" }}. .{{ b|ljust:"5" }}.{% endautoescape %}', {"a": "a&b", "b": mark_safe("a&b")}, u".a&b . .a&b ."), 169 252 'filter-ljust02': ('.{{ a|ljust:"5" }}. .{{ b|ljust:"5" }}.', {"a": "a&b", "b": mark_safe("a&b")}, u".a&b . .a&b ."), … … def get_filter_tests(): 267 350 'filter-iriencode02': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': '?test=1&me=2'}, '?test=1&me=2'), 268 351 'filter-iriencode03': ('{{ url|iriencode }}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), 269 352 'filter-iriencode04': ('{% autoescape off %}{{ url|iriencode }}{% endautoescape %}', {'url': mark_safe('?test=1&me=2')}, '?test=1&me=2'), 353 'filter-iriencode05': ('{{ a|iriencode }}', {'a': u'S\xf8r-Tr\xf8ndelag'}, u'S%C3%B8r-Tr%C3%B8ndelag'), 354 'filter-iriencode06': ('{{ a|urlencode|iriencode }}', {'a': u'fran\xe7ois & jill'}, u'fran%C3%A7ois%20%26%20jill'), 270 355 271 356 # urlencode 272 357 'filter-urlencode01': ('{{ url|urlencode }}', {'url': '/test&"/me?/'}, '/test%26%22/me%3F/'), 273 358 'filter-urlencode02': ('/test/{{ urlbit|urlencode:"" }}/', {'urlbit': 'escape/slash'}, '/test/escape%2Fslash/'), 359 'filter-urlencode03': ('{{ a|urlencode }}', {'a': u'fran\xe7ois & jill'}, u'fran%C3%A7ois%20%26%20jill'), 360 'filter-urlencode04': ('{{ a|urlencode }}', {'a': 1}, u'1'), 274 361 275 362 # Chaining a bunch of safeness-preserving filters should not alter 276 363 # the safe status either way. … … def get_filter_tests(): 302 389 'autoescape-stringfilter03': (r'{{ safe|capfirst }}', {'safe': SafeClass()}, 'You > me'), 303 390 'autoescape-stringfilter04': (r'{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}', {'safe': SafeClass()}, 'You > me'), 304 391 305 'escapejs01': (r'{{ a|escapejs }}', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'}, 'testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E'), 306 'escapejs02': (r'{% autoescape off %}{{ a|escapejs }}{% endautoescape %}', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'}, 'testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E'), 307 392 'escapejs01': ('{{ a|escapejs }}', {'a': u'testing\r\njavascript \'string" <b>escaping</b>'}, u'testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E'), 393 'escapejs02': ('{% autoescape off %}{{ a|escapejs }}{% endautoescape %}', {'a': u'testing\r\njavascript \'string" <b>escaping</b>'}, u'testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E'), 394 'escapejs03': ('{{ a|escapejs }}', {'a': u'"double quotes" and \'single quotes\''}, u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027'), 395 'escapejs04': ('{{ a|escapejs }}', {'a': ur'\ : backslashes, too'}, u'\\u005C : backslashes, too'), 396 'escapejs05': ('{{ a|escapejs }}', {'a': u'and lots of whitespace: \r\n\t\v\f\b'}, u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008'), 397 'escapejs06': ('{{ a|escapejs }}', {'a': ur'<script>and this</script>'}, u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E'), 398 'escapejs07': ('{{ a|escapejs }}', {'a': u'paragraph separator:\u2029and line separator:\u2028'}, u'paragraph separator:\\u2029and line separator:\\u2028'), 308 399 309 400 # length filter. 310 401 'length01': ('{{ list|length }}', {'list': ['4', None, True, {}]}, '4'), … … def get_filter_tests(): 336 427 'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'), 337 428 338 429 # Test that joining with unsafe joiners don't result in unsafe strings (#11377) 339 'join05': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': ' & '}, 'alpha & beta & me'), 340 'join06': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta & me'), 341 'join07': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': ' & ' }, 'alpha & beta & me'), 342 'join08': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta & me'), 343 430 'join05': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': ' & '}, 'alpha & beta & me'), 431 'join06': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta & me'), 432 'join07': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': ' & ' }, 'alpha & beta & me'), 433 'join08': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta & me'), 434 344 435 'date01': (r'{{ d|date:"m" }}', {'d': datetime(2008, 1, 1)}, '01'), 345 436 'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'), 346 437 #Ticket 9520: Make sure |date doesn't blow up on non-dates