rx.location.generate html-encodes the "&" delimiters

When I display the string returned by rx.location.generate, it is html-encoding the &'s. (i.e., “amp;”)

To me, it doesn’t seem correct to html-encode the “&” in this case. Is this a bug, or am I missing something?

I bring it up because it’s actually causing problems when I use it in a JavaScript “open” to bring up the location in a popup.

This is a successful workaround for the issue:


#set($linktobig = $rx.location.generate($sys.assemblyItem,"cnProductImage_BinaryTemplate"))
#set ($linktobigclean = $linktobig.replaceAll("&","&"))
	

This is intentional. The XHTML specification is very clear about this: all documents must be well formed, and that includes URLs as well. See http://www.w3.org/TR/xhtml1/

All modern web browsers will work with URLs that contain &. It’s only things like Javascript that get in the way. If you are careful about how you code things, you should be able to handle these URLs in your JavaScript as well.

Interesting. So it sounds like there may be a way to call the JavaScript open without using my workaround…

I don’t know. Intuitively it seems like the ampersand shouldn’t be encoded when it is being used as a delimiter, but only if it is part of the name or value. “=” doesn’t get encoded, for example. And how can you tell if the ampersand is a delimiter or not if it is encoded everywhere?

OK. I found the answer to my own question. I guess you url-encode (as opposed to html-encode) an ampersand as %26 if you want it to be part of a value.

OK. I put in a more correct fix:


#set($linktobig = $rx.location.generate($sys.assemblyItem,"cnProductImage_BinaryTemplate"))

	

<script lang="javascript">
   function popup(href )
{
   window.open (href, "zoom", "width=1042,height=912,toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes")

}
</script>
<a onclick="popup(this);return false;" href="${linktobig}">link</a>

It works in Firefox and IE (the versions I have, anyway) and I am running it by our Html guy, to make sure it is acceptable.

Hi April

You can also use $rx.codec.decodeFromXml(string) as well.

I’ve used this on a couple occasions when needing a url for javascript. eg google maps

Cheers
James

Any chance the render application that assembles previews of pages could be modified to allow use of semicolons in place of ampersands to delimit name/value pairs in query strings? This would avoid the problem.

Unfortunately, we are using some Flash on some of our pages. The Flash reads XML files generated by Rhythmyx, in which are specified the URLs of the images it displays, which are also kept in Rhythmyx. It works when published, but when previewing the Flash stumbles over the ampersands. But encoding them (to %26) doesn’t work either, because the render application in 6.5.2 cannot decode the URLs requested by the Flash, so the preview is lacking all the parameters it needs to know which content ID, variant ID, etc to use to assemble the XML or the images.

Very handy, thanks!