Cleaning up stack URLs

Devin Asay devin_asay at byu.edu
Tue Apr 24 15:28:52 EDT 2007


On Apr 24, 2007, at 12:46 PM, Mark Smith wrote:

> I think UrlEncode is exactly what you're after, isn't it?
>
> from the docs:
>
> Returns a string that has been transformed so that it can be posted  
> to an HTTP server as a URL.

Right, I checked that out first thing. But URLencode is for  
formatting a URL to be *posted* to a server. When you request a file  
with go stack URL, you are invoking a GET operation on the server,  
not a POST. The string formatting requirements appear to be  
different. For example, I want to open a stack whose stackfile name  
contains a space:

     go stack URL "http://server.com/My Stack.rev"

This fails in Revolution. If I try to access the same URL in my web  
browser, the browser reformats it like this before sending it:

     http://server.com/My%20Stack.rev

URLencode, on the other hand, escapes virtually all non-alphanumeric  
chars:

     put URLencode("http://server.com/My Stack.rev")
     --> http%3A%2F%2Fserver.com%2FMy+Stack.rev

A URL encoded like this doesn't even make it to the server.

But if I do this:

    put "http://server.com/My Stack.rev" into myURL
    replace space with "%20" in myURL
    go stack URL myURL

It works perfectly. So it appears that, since I can't predict what  
stack names someone might try to retrieve with this stack, I'm going  
to have to write my own function that checks for unsafe characters in  
a URL string and escapes them. Before I do this I want to find out if  
I'm overlooking something, if anyone has done something like this  
before, and which characters really need to be escaped in the URL  
string.

Any suggestions are appreciated.

Devin

>
>> I'm working on a stack that launches stacks from the web with 'go  
>> stack URL'.
>>
>> I know there are certain characters that are illegal or unsafe in  
>> URL strings. (See http://tools.ietf.org/html/rfc1738) These  
>> include space, quote and a number of others. Most web browsers  
>> automatically escape these characters for you, so, e.g., a space  
>> is converted to '%20' before the browser sends the request to the  
>> server.
>>
>> I'm about to start writing a function that checks a potential  
>> stack URL for illegal and unsafe characters and converts them to  
>> escape sequences, but I don't want to reinvent the wheel if such a  
>> thing already exists.
>>
>> Am I right that there is no equivalent functionality built into  
>> Rev? I know about URLEncode(), of course, but that serves a  
>> different purpose--formatting strings for POSTing, rather than  
>> formatting strings for retrieving files from a server (a GET  
>> request?) Am I understanding this correctly?
>>
>> A related issue is, are there characters that are disallowed as  
>> filenames for rev stackfiles? I can't find any such list anywhere.  
>> I suppose this would be determined by the host OS?


Devin Asay
Humanities Technology and Research Support Center
Brigham Young University




More information about the use-livecode mailing list