Search code examples
actionscript-3urlvariables

AS3: Use the underscore character in a URLVariables variable name


Is it possible to use the underscore character in a URLVariables variable name? For instance, the following code outputs "my%5Fusername=foo" instead of "my_username=foo".

import flash.net.URLVariables;
var variables : URLVariables = new URLVariables("my_username=foo");  
trace(variables.toString());

Just as in the trace, the "%5F" shows up instead of the underscore in the request. Is there some way I can get the underscore character to show up instead?


Solution

  • Simply don't use URLVariables class, it's known to do other things wrong too. This URL RFC calls the underscore a special character and puts it in the same category as alphanumeric, saying that no encoding is needed. This RFC calls the part where you'd have the variables as "query" and allocates pchar to it, describing pchar as containing underscore character.

    In practice URI containing underscore characters doesn't seem to give problem to browsers or servers, so it's just plain wrong to encode it.

    EDIT: from further reading it looks more like that this is rather an undesirable behavior, then a mistake (the URI normalizer would know to revert the encoded underscore to it's original look), still, encoding underscore is the same as encoding letters of English alphabet - wasteful and stupid.