[Catalyst] Escaping of "argument" of private path

John M. Dlugosz wxju46gefd at snkmail.com
Tue Mar 15 07:02:28 GMT 2011

On 3/15/2011 1:38 AM, Octavian Rasnita orasnita-at-gmail.com |Catalyst/Allow to home| wrote:
> uri_for() escapes each component, but I guess that it doesn't escape it if it contains a 
> slash in it.
> For example, you can do:
> <img src="[% c.uri_for('/static', 'ham and eggs.jpg').path %]">
> It will print:
> <img src="/static/ham%20and%20eggs.jpg">
> Octavian

I see... it wants you to pass separate arguments rather than building the path first.

I was thinking that uri_for might be more trouble than it's worth since I don't like 
fully-qualified URLs in my generated source anyway.  But if it escapes (sometimes?) then 
that is indeed more helpful.

<img src="[% c.uri_for("/static/gallery",rec.dirname,rec.filename) %]" alt="photo" />

That works (using Smart_URI settings to leave off the host).  But it did not escape out 
the '&' in the filename!  Is that a bug?  I notice you changes my example from '&' to 
'and' -- that's cheating!

<img src="[% "/static/gallery/${rec.dirname}/${ rec.filename | uri }" %]" alt="photo" />

gives the correct answer: ham%20%26%20eggs.jpeg

More information about the Catalyst mailing list