[ZPT] I don't want "&" to be URL escaped in tal:attributes
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)
On Wednesday 16 January 2002 12:02, you wrote:
> Date: Wed, 16 Jan 2002 11:30:34 -0500
> From: Evan Simpson <firstname.lastname@example.org>
> Organization: Zope Corporation
> To: email@example.com
> CC: firstname.lastname@example.org, email@example.com
> 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=
> > 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: firstname.lastname@example.org [mailto:email@example.com]On Behalf Of
> >>I want to render a URL by tal:attributes:
> >><a href="" tal:attributes="href python:
> >>the & in '?var1=A&var2=B' will be "escaped" to &
> >>That make unexpected URL to be generated,
> >>How to keep "&" to be "&" not "&"
> This is now in the FAQ, at:
> Evan @ Zope