Spaces in URLEncode?

Dar Scott dsc at swcp.com
Fri Jul 19 14:22:01 EDT 2002


On Thursday, July 18, 2002, at 10:30 PM, David Egbert wrote:

> I always thought that spaces were converted to "%20" in a URL 
> string and the
> + sign was used for JavaScript.  Am I off base here?  Is there another
> function that will convert the spaces to "%20"?

I was surprised when I saw this, too.

Use "replace" to do that.  See below.

I believe all the URLEncode does is replace the space with plus (+) 
and replace those not ASCII letters or digits with the %nn 
encoding.  Use it as a tool to help in your coding of your URL 
functions.

The query string is separated from the path of the URL by a 
question mark (?).  In the query string each space is converted to 
a plus.

The URLEncode might be sufficient for the query part (except for 
FORM pairs).

For the components of the path part, this should be close (off the 
top of my head)...

function encodeURLpathComponent theURL
    put URLencode(theURL) into theEncoded
    replace "+" with "%20" in theEncoded
    return theEncoded
end encodeURLpathComponent

However, if the URL is hard coded, you can convert by hand and do 
not need that function.  If you are making queries you can use 
URLencode for for the query part.  If you are using FORM queries, 
use URL encode on each name and value before building your query.  
Do not apply it afterward.  I think ISINDEX encoding is OK with 
simply URLencode (I'm not sure about ampersand and semicolon).  For 
ISMAP, you may need to avoid encoding the comma.

So...  In general a space might be encoded as a + or %20.  No doubt 
thunk up to make your life harder.

Dar Scott









More information about the Use-livecode mailing list