[ZPT] I don't want  "&" to be URL escaped in tal:attributes

Wade Leftwich wade@okaynetwork.com
Thu, 17 Jan 2002 09:52:06 -0500

the FAQ sez:
Q15: When I use tal:attributes to set the src or href attribute of a tag, it 
turns my ampersands into &s! How can I stop it?
     You can't, and shouldn't. According to the standard, escaping is the 
proper thing to do here. It works properly with every browser we've tried.
And that's right, as far as it goes. However, I've just done a project where 
I used ZPT to generate emails in text, AOL and html versions. The Aol email 
client is sort-of-html-capable, but it cannot handle escaped ampersands in 
Urls (at least at or below Aol v 5). And in many email clients displaying 
text, the 'make a Url live' feature doesn't work if escaped ampersands are 

I got around this in 2 different ways.

For the text version, I just unescaped the entire page after it was 
generated: s.replace('&', '&')

for a bit finer control, something like this:
def makeLink(url, name):
    url = url.replace('&', '&')
    return '<a href="%s">%s</a>' % (url, name)

Wade Leftwich
Ithaca, NY

On Wednesday 16 January 2002 12:02, you wrote:
> Date: Wed, 16 Jan 2002 11:30:34 -0500
> From: Evan Simpson <evan@zope.com>
> Organization: Zope Corporation
> To: jpeterso@rangebroadband.com
> CC: iap@y2fun.com, zpt@zope.org
> Subject: Re: [ZPT] I don't want  "&" to be URL escaped in tal:attribu=
> how to do?
> Jeff Peterson wrote:
> > We ran into this problem on a project just last week.  We were un=
able to
> > find a way to actually "escape" the ampersand but we were able to w=
> > around it using simple direct traversal.  This may or may not be =
> > to you but it worked for us so I thought I would at least mention it 
> >
> >>From: zpt-admin@zope.org [mailto:zpt-admin@zope.org]On Behalf Of
> >>iap@y2fun.com
> >>I want to render a URL by tal:attributes:
> >><a href="" tal:attributes="href python:
> >>here.absolute_url()+'?var1=A&var2=B'">
> >>the & in '?var1=A&var2=B' will be "escaped" to &amp;
> >>That make unexpected URL to be generated,
> >>How to keep "&" to be "&" not "&amp;"
> This is now in the FAQ, at:
> http://dev.zope.org/Wikis/DevSite/Projects/ZPT/FAQ#15
> Cheers,
> Evan @ Zope