Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Fix escaping
Browse files Browse the repository at this point in the history
I wasn't placing htmlescape into the right context dictionary. Since
we have a default noop escape function in the context already, we
don't need the unescaped renderer again after all. Circles! :)
  • Loading branch information
chadwhitacre committed Feb 10, 2015
1 parent 3c43a6b commit 73996eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
8 changes: 3 additions & 5 deletions gratipay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from gratipay.security import authentication, csrf, x_frame_options
from gratipay.utils import cache_static, i18n, set_cookie, timer
from gratipay.version import get_version
from gratipay.renderers import jinja2_htmlescaped, jinja2_unescaped
from gratipay.renderers import jinja2_htmlescaped

import aspen
from aspen import log_dammit
Expand Down Expand Up @@ -58,12 +58,10 @@ def _set_cookie(response, *args, **kw):

website.renderer_factories['jinja2_htmlescaped'] = jinja2_htmlescaped.Factory(website)
website.default_renderers_by_media_type['text/html'] = 'jinja2_htmlescaped'

website.renderer_factories['jinja2_unescaped'] = jinja2_unescaped.Factory(website)
website.default_renderers_by_media_type['text/plain'] = 'jinja2_unescaped'
website.default_renderers_by_media_type['text/plain'] = 'jinja2' # unescaped is fine here

website.renderer_factories['jinja2'].Renderer.global_context = {
# This is shared via class inheritance with jinja2_{html,un}escaped.
# This is shared via class inheritance with jinja2_htmlescaped.
'b64encode': base64.b64encode,
'enumerate': enumerate,
'float': float,
Expand Down
8 changes: 7 additions & 1 deletion gratipay/renderers/jinja2_htmlescaped.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ def render_content(self, context):
# template authors shouldn't normally need to use this function, but
# having it in the simplate context makes it easier to implement i18n.

context['escape'] = htmlescape
context['escape'] = context['request'].context['escape'] = htmlescape

# ^^^ Yes, this is fugly. We need the escaping function in the
# request.context dictionary because that's where the i18n functions
# look for it, and we need it in `context` (which is a Jinja2 context,
# which is not identical with request.context) so that it's properly
# available inside of simplate pages 3+.

return base.Renderer.render_content(self, context)

Expand Down
17 changes: 0 additions & 17 deletions gratipay/renderers/jinja2_unescaped.py

This file was deleted.

0 comments on commit 73996eb

Please sign in to comment.