Skip to content
Myr

Add urlescape to default filters.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Aaron Swartz · committed by Aaron Swartz · parent 80b4fe6 · Browse files · 2 files+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−2 removed

  • other:+14 added−2 removed

2 files+14 added−2 removed

modified:jinja2/testsuite/filters.py+5 added-1 removed
364 unmodified lines
365 tmpl = env.from_string('{{ "<div>foo</div>"|safe }}')366 assert tmpl.render() == '<div>foo</div>'367 tmpl = env.from_string('{{ "<div>foo</div>" }}')368 assert tmpl.render() == '&lt;div&gt;foo&lt;/div&gt;'369 370 def test_urlescape(self):371 env = Environment(autoescape=True)372 tmpl = env.from_string('{{ "Hello, world!"|urle }}')373 assert tmpl.render() == 'Hello%2C%20world%21'374370375def suite():376 suite = unittest.TestSuite()377 suite.addTest(unittest.makeSuite(FilterTestCase))378 return suite
modified:jinja2/filters.py+9 added-1 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import re12import math13import urllib14from random import choice15from operator import itemgetter16from itertools import imap, groupby17from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode
51 unmodified lines
69 if hasattr(value, '__html__'):70 value = value.__html__()71 return escape(unicode(value))7273def do_urlescape(value):74 """Escape for use in URLs."""75 return urllib.quote(value.encode('utf8'))7677@evalcontextfilter78def do_replace(eval_ctx, s, old, new, count=None):79 """Return a copy of the value with all occurrences of a substring
720 unmodified lines
800 'abs': abs,801 'round': do_round,802 'groupby': do_groupby,803 'safe': do_mark_safe,800 'xmlattr': do_xmlattr804 'xmlattr': do_xmlattr,805 'urlescape': do_urlescape,806 'urle': do_urlescape,807 'urlencode': do_urlescape,808 'urlquote': do_urlescape809}