Jump to content

URL-Safe Conversion


T-Square
 Share

This topic is 5772 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Another thread got me to thinking about the problem of translating source text from Filemaker into truly "safe" URL encoding. Using online references about the characters that need to be escaped, I came up with the following long but simple function.

It takes care of just about any character that could be misinterpreted by an outside program in a URL--at least those I could find when I dredged online for URL encoding specifications. The only exception made here was for the space character.

Usage is simple: just feed text into the function, and all possibly suspicious characters will be changed to their hexcode equivalents. I have not tested it in all situations, but initial test show it to work in Windows with Pegasus mail.

Any improvements are welcome!

Function URLEscape(Src)

---------------------------------------

Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute( Substitute(Src; "%"; "%25"); "$"; "%24"); "#"; "%23"); "&"; "%26"); "/"; "%2F"); ":"; "%3A"); "; "; "%3B"); "<"; "%3C"); "="; "%3D"); ">"; "%3E"); "?"; "%3F"); "@"; "%40"); "["; "%5B"); ""; "%5C"); "]"; "%5D"); "^"; "%5E"); "`"; "%60"); "{"; "%7B"); "|"; "%7C"); "}"; "%7D"); "~"; "%7E"); "¶"; "%0D%0A"); "!"; "%21"); """; "%22"); "("; "%28"); ")"; "%29"); "'"; "%27"); ","; "%2C"); "*"; "%2A")

Link to comment
Share on other sites

Nested substitutes are not required in version 7. You can write your function much more conveniently as:

Substitute ( Src ;

[ "%" ; "%25" ] ;

[ "$" ; "%24" ] ;

[ "#" ; "%23" ] ;

[ "&" ; "%26" ] ;

[ "/" ; "%2F" ] ;

[ ":" ; "%3A" ] ;

[ ";" ; "%3B" ] ;

[ "<" ; "%3C" ] ;

[ "=" ; "%3D" ] ;

[ ">" ; "%3E" ] ;

[ "?" ; "%3F" ] ;

[ "@" ; "%40" ] ;

[ "[" ; "%5B" ] ;

[ "" ; "%5C" ] ;

[ "]" ; "%5D" ] ;

[ "^" ; "%5E" ] ;

[ "`" ; "%60" ] ;

[ "{" ; "%7B" ] ;

[ "|" ; "%7C" ] ;

[ "}" ; "%7D" ] ;

[ "~" ; "%7E" ] ;

[ "¶" ; "%0D%0A" ] ;

[ "!" ; "%21" ] ;

[ """ ; "%22" ] ;

[ "(" ; "%28" ] ;

[ ")" ; "%29" ] ;

[ "'" ; "%27" ] ;

[ "," ; "%2C" ] ;

[ "*" ; "%2A" ]

)

Link to comment
Share on other sites

This topic is 5772 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.