Issue with Tilt::ErubisTemplate modifying options hash and Sinatra

62 views
Skip to first unread message

Geoff Buesing

unread,
Mar 25, 2010, 7:15:12 PM3/25/10
to Tilt
I came across this issue while trying to render an erubis template in
Sinatra with a layout and the new :escape_html => true feature, ex:

erb :foo, :layout => :bar, :escape_html => true

Tilt::ErubisTemplate#prepare modifies the options hash; it merges in
{:preamble => false, :postamble => false}, and
deletes :outvar, :engine_class, and :escape_html keys.

Issue arises when using Sinatra layouts because Sinatra reuses the
same options hash to render the layout after it has rendered the inner
template. The result is: the inner template is rendered
with :escape_html option, but the layout is not.

(Note that if you use Sinatra's set method to set :escape_html
globally, e.g. set :erubis, :escape_html => true, this option will be
merged in for both the layout and the template, so the issue won't
occur.)

Duping the options hash in Tilt::Template#initialize seems to fix
things. I'd be happy to prepare a patch.

Geoff Buesing

unread,
Apr 6, 2010, 5:35:21 PM4/6/10
to Tilt
Just following up on this issue. I've got a fix for it in my fork:
http://github.com/gbuesing/tilt/commit/5fdcb64d4003785447de18afd69d0faca5b38dc5

Ryan Tomayko

unread,
Apr 11, 2010, 5:53:07 AM4/11/10
to til...@googlegroups.com, gbue...@gmail.com
On Tue, Apr 6, 2010 at 2:35 PM, Geoff Buesing <gbue...@gmail.com> wrote:
> Just following up on this issue. I've got a fix for it in my fork:
> http://github.com/gbuesing/tilt/commit/5fdcb64d4003785447de18afd69d0faca5b38dc5
>

Merged a few days ago. I'll get a release out soonish. Sinatra will
pick up the latest installed version of Tilt so that should fix all
the issues people have been having with this.

Thanks,
Ryan

> On Mar 25, 6:15 pm, Geoff Buesing <gbues...@gmail.com> wrote:
>> I came across this issue while trying to render an erubis template in
>> Sinatra with a layout and the new :escape_html => true feature, ex:
>>
>>     erb :foo, :layout => :bar, :escape_html => true
>>
>> Tilt::ErubisTemplate#prepare modifies the options hash; it merges in
>> {:preamble => false, :postamble => false}, and
>> deletes :outvar, :engine_class, and :escape_html keys.
>>
>> Issue arises when using Sinatra layouts because Sinatra reuses the
>> same options hash to render the layout after it has rendered the inner
>> template. The result is: the inner template is rendered
>> with :escape_html option, but the layout is not.
>>
>> (Note that if you use Sinatra's set method to set :escape_html
>> globally, e.g. set :erubis, :escape_html => true, this option will be
>> merged in for both the layout and the template, so the issue won't
>> occur.)
>>
>> Duping the options hash in Tilt::Template#initialize seems to fix
>> things. I'd be happy to prepare a patch.
>
>

> --
> To unsubscribe, reply using "remove me" as the subject.
>

Reply all
Reply to author
Forward
0 new messages