OUI

8.14 Why can't I pass variables with spaces and apostrophes?

To pass variable names and content to the server, you might do something like this:

<go href="/cgi-bin/somescript?name=$(name)&age=$(age)"/>

If the user inputs a name string that contains special characters such as a spaces or apostrophes, it will result in an illegal URL. If the user typed "Espen Lyngaas" and I'm 32 years old, the URL would be:

/cgi-bin/somescript?name="Espen Lyngaas"&age;=I'm 32 years old

The server that receives this URL is unlikely to accept that. The solution to the problem is to enable so called character escaping when the variable is replaced. The general syntax is $(variablename:escapemode) where variablename is the name of the variable and escapemode is noesc which means do not escape or unescape the variable, escape which means that the variable should be escaped, and unescape which means that the variable should be converted from an escaped format to a normal format. The following will solve the above problem:

<go href="/cgi-bin/somescript?name=$(name:escape)&age=$(age:escape)"/>

This will produce an URL like this:

/cgi-bin/somescript?name=%22Espen+Lyngaas%22&age;=I%27m+32+years+old

Escaping can be used wherever variable replacement is used in the WML code, for instance <setvar name="var1" value="$(myname:escape)">.

[ Main ]   [ 08 - Troubleshooting ]