Difference between revisions of "LlEscapeURL"

From Second Life Wiki
Jump to navigation Jump to search
m (replaced example script with the one from llUnescapeURL which makes it more clear what happens both ways)
m (oops)
Line 9: Line 9:
|caveats=The function is not appropriate for escaping a {{LSLP|url}} all at once, because the <code>":"</code> after the protocol, and all of the <code>"/"</code> characters delimiting the various parts, will be escaped. Instead, build the {{LSLP|url}} in parts; escaping parts of the path and query string arguments as needed.
|caveats=The function is not appropriate for escaping a {{LSLP|url}} all at once, because the <code>":"</code> after the protocol, and all of the <code>"/"</code> characters delimiting the various parts, will be escaped. Instead, build the {{LSLP|url}} in parts; escaping parts of the path and query string arguments as needed.


Sample {{LSLP|url}}: [https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322/foo/bar?arg=gra {{HoverTextStyle|style=color:green;|<nowiki>https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322</nowiki>|2={{String|x-script-url}} = {{String|https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322}}}}{{HoverTextStyle|style=color:blue;|/foo/bar|2={{String|x-path-info}} = {{String|/foo/bar}}}}?{{HoverTextStyle|style=color:red;|1=arg=gra|2={{String|x-query-string}} = {{String|1=arg=gra}}}}]
Sample URL: [https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322/foo/bar?arg=gra {{HoverTextStyle|style=color:green;|<nowiki>https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322</nowiki>|2={{String|x-script-url}} = {{String|https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322}}}}{{HoverTextStyle|style=color:blue;|/foo/bar|2={{String|x-path-info}} = {{String|/foo/bar}}}}?{{HoverTextStyle|style=color:red;|1=arg=gra|2={{String|x-query-string}} = {{String|1=arg=gra}}}}]


{{{!}} class="lltable" style="font-size: 85%; text-align: center; width: auto; border=1px;"
{{{!}} class="lltable" style="font-size: 85%; text-align: center; width: auto; border=1px;"
! description of {{LSLP|url}} part
! description of URL part
! example
! example
{{!}}-
{{!}}-
{{!}} Base {{LSLP|url}}
{{!}} Base URL
{{!}} <font color="green"><nowiki>https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322</nowiki></font>
{{!}} <font color="green"><nowiki>https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322</nowiki></font>
{{!}}-
{{!}}-
Line 21: Line 21:
{{!}} <font color="blue">/foo/bar</font>
{{!}} <font color="blue">/foo/bar</font>
{{!}}-
{{!}}-
{{!}} Any query arguments, the text past the first "?" in the {{LSLP|url}}
{{!}} Any query arguments, the text past the first "?" in the URL
{{!}} <font color="red">arg=gra</font>
{{!}} <font color="red">arg=gra</font>
{{!}}}
{{!}}}

Revision as of 01:10, 24 January 2014

Summary

Function: string llEscapeURL( string url );
0.0 Forced Delay
10.0 Energy

Returns a string that is the escaped/encoded version of url, replacing spaces with "%20" etc. The function will escape any character not in [a-zA-Z0-9] to "%xx" where "xx" is the "Wikipedia logo"hexadecimal value of the character in "Wikipedia logo"UTF-8 "Wikipedia logo"byte form.

• string url A valid and unescaped URL.

To clarify, numbers and ASCII7 alphabetical characters are NOT escaped. If a character requires more then one byte in "Wikipedia logo"UTF-8 "Wikipedia logo"byte form then it returns multiple "%xx" sequences chained together.

This function is similar to functions (e.g. rawurlencode, encodeURIComponent) found in many other languages: 
PHP
rawurlencode
ECMAScript
encodeURIComponent

Caveats

The function is not appropriate for escaping a url all at once, because the ":" after the protocol, and all of the "/" characters delimiting the various parts, will be escaped. Instead, build the url in parts; escaping parts of the path and query string arguments as needed.

Sample URL: https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322/foo/bar?arg=gra

description of URL part example
Base URL https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322
Trailing path information /foo/bar
Any query arguments, the text past the first "?" in the URL arg=gra

Examples

<lsl> string str = "http://wiki.secondlife.com/wiki/LSL Portal";

default {

   state_entry()
   {
       llOwnerSay("Plain string:\n\t" + str);
       // output: "http://wiki.secondlife.com/wiki/LSL Portal"

       llOwnerSay("Escaped string:\n\t" + llEscapeURL(str));
       // output: "http%3A%2F%2Fwiki%2Esecondlife%2Ecom%2Fwiki%2FLSL%20Portal"

       llOwnerSay("Escaped string unescaped again:\n\t" + llUnescapeURL( llEscapeURL(str) ));
       // output: "http://wiki.secondlife.com/wiki/LSL Portal"

       // because escaping and unescaping are exact opposite
       // and unescaping an escaped string returns the original


       //  For readability's sake it would make more sense to do:
       llOwnerSay("For readability's sake:\n\t" + "http://wiki.secondlife.com/wiki/" + llEscapeURL("LSL Portal"));
       // output: "http://wiki.secondlife.com/wiki/LSL%20Portal"
   }

}

</lsl>

See Also

Functions

• llUnescapeURL

Articles

• UTF-8
• Base64

Deep Notes

History

  • Prior to SL versions 1.19.1.81992, this function was limited to returning a maximum of 254 characters. SVC-470

Signature

function string llEscapeURL( string url );