Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2193 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

Mako 'h' filter is mangled by turbogears default template variables

Reported by: kikidonk Owned by: faide
Priority: normal Milestone: 2.0b6
Component: TurboGears Version: trunk
Severity: normal Keywords:
Cc:

Description

The mako documentation about filtering:  http://www.makotemplates.org/docs/filtering.html

In theory you're supposed to be able to do ${something | h} to have the content of the template variable 'something' html-escaped in a mako template.

However at http://trac.turbogears.org/browser/trunk/tg/render.py#L99 a default variable is passed to the template that is also named 'h' which will override the mako builtin filter 'h' resulting in a weird exception when using it. This is somewhat unexpected.

I know that in the configuration, turbogears setup a default html-escape filter for mako, so in theory the 'h' filter shouldn't be needed but there are some cases where one would want manual control on things (ie. prevent escape then escape a subset of the string or such) and to do that one has to use the 'escape' function exported by TG.

I don't know what could be a correct solution here..

Change History

comment:1 Changed 10 years ago by mramm

hmm, I'm OK with not placing helpers into the template context as h, but just as helpers. But this would need to be done now if it is going to be done, and it will likely break some people's old code so I'm very hesitant to do it.

--Mark

comment:2 follow-up: ↓ 3 Changed 10 years ago by kikidonk

Well I guess this change should be documented, with a transition phase were a deprecation warning is issued upon use of 'h' or something like that.

Else we could just add the mako's 'h' variable under a different name in the standard tg_vars although i dislike this options. In any case it should be in the tg2 docs that you can't use the 'h' var with mako templates because it is overwritten. (Also it should be documented that there is a default html-escaping filter setup, which is not the case with vanilla mako)

comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 10 years ago by jorge.vargas

Replying to kikidonk:

Well I guess this change should be documented, with a transition phase were a deprecation warning is issued upon use of 'h' or something like that.

Else we could just add the mako's 'h' variable under a different name in the standard tg_vars although i dislike this options. In any case it should be in the tg2 docs that you can't use the 'h' var with mako templates because it is overwritten.

I don't like either one of them. both deserve to be 'h' perhaps we should reconsider the template_vars thing tg passes to provide name collision.

(Also it should be documented that there is a default html-escaping filter setup, which is not the case with vanilla mako)

agreed, but this is in place to assume you are rendering a webpage.

comment:4 in reply to: ↑ 3 Changed 10 years ago by kikidonk

Replying to jorge.vargas:

(Also it should be documented that there is a default html-escaping filter setup, which is not the case with vanilla mako)

agreed, but this is in place to assume you are rendering a webpage.

Right so that's another bug i'd say ? Imagine I wanted to render a plain-text template for inclusion in an email using mako. Currently if i just use the tg.render function, the fields will be html-escaped which doesn't make sense in a text-template ?

Should I open a new bug for that ?

comment:5 Changed 10 years ago by mramm

Yea, make a new ticket for that.

In the meantime I'm going to fix just the h issue for b6, and then close this ticket.

comment:6 Changed 10 years ago by mramm

h is not available in the template any more, use helpers instead.

comment:7 Changed 10 years ago by mramm

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.