Difference between revisions of "LlEscapeURL"

From Second Life Wiki
Jump to: navigation, search
m
m (added some background information and code tags, wikipedia links, etc.)
Line 1: Line 1:
 
{{LSL_Function
 
{{LSL_Function
 
|func_id=307|func_sleep=0.0|func_energy=10.0
 
|func_id=307|func_sleep=0.0|func_energy=10.0
|func=llEscapeURL|return_type=string|p1_type=string|p1_name=url
+
|func=llEscapeURL|return_type=string|p1_type=string|p1_name=url|p1_desc=A valid and unescaped URL.
|func_footnote=To clarify, numbers and ASCII7 alphabetical characters are NOT escaped. If a character requires more then one byte in UTF-8 byte form then it returns multiple %xx sequences chained together.
+
|func_footnote=To clarify, numbers and ASCII7 alphabetical characters are NOT escaped. If a character requires more then one byte in {{Wikipedia|UTF-8|UTF-8}} {{Wikipedia|Byte|byte}} form then it returns multiple <code>"%xx"</code> sequences chained together.
 
|func_desc
 
|func_desc
|return_text=that is the escaped/encoded version of {{LSLPT|url}}, replacing spaces with ''%20'' etc. The function will escape any character not in {a-z, A-Z, 0-9} to ''%xx'' where "xx" is the hexadecimal value of the character in UTF-8 byte form.
+
|return_text=that is the escaped/encoded version of {{LSLPT|url}}, replacing spaces with <code>"%20"</code> etc. The function will escape any character not in {{HoverText|<nowiki>[a-zA-Z0-9]</nowiki>|a-z, A-Z, 0-9}} to <code>"%xx"</code> where <code>"xx"</code> is the {{Wikipedia|Hexadecimal|hexadecimal}} value of the character in {{Wikipedia|UTF-8|UTF-8}} {{Wikipedia|Byte|byte}} form.
 
|spec
 
|spec
 
|other_languages={{LSL OL|PHP|[http://php.net/manual/en/function.rawurlencode.php rawurlencode]}}{{LSL OL|{{HoverText|ECMAScript|JavaScript, ActionScript, etc}}|[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent encodeURIComponent]}}
 
|other_languages={{LSL OL|PHP|[http://php.net/manual/en/function.rawurlencode.php rawurlencode]}}{{LSL OL|{{HoverText|ECMAScript|JavaScript, ActionScript, etc}}|[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent 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.
+
|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}}}}]
 +
 
 +
{{{!}} class="lltable" style="font-size: 85%; text-align: center; width: auto; border=1px;"
 +
! description of {{LSLP|url}} part
 +
! example
 +
{{!}}-
 +
{{!}} Base {{LSLP|url}}
 +
{{!}} <font color="green"><nowiki>https://sim3015.aditi.lindenlab.com:12043/cap/a7717681-2c04-e4ac-35e3-1f01c9861322</nowiki></font>
 +
{{!}}-
 +
{{!}} Trailing path information
 +
{{!}} <font color="blue">/foo/bar</font>
 +
{{!}}-
 +
{{!}} Any query arguments, the text past the first "?" in the {{LSLP|url}}
 +
{{!}} <font color="red">arg=gra</font>
 +
{{!}}}
 
|constants
 
|constants
 
|examples=<lsl>
 
|examples=<lsl>

Revision as of 01:50, 24 January 2014

Summary

Function: string llEscapeURL( string url );

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 hexadecimal value of the character in UTF-8 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 UTF-8 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
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> // Provides a clickable link to the LSL Portal by escaping the space in the title // "LSL Portal" here becomes "LSL%20Portal"

string title = "LSL Portal";

default {

   state_entry()
   {
       llOwnerSay("http://wiki.secondlife.com/wiki/" + llEscapeURL(title));
   }

}

</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

Search JIRA for related Issues

Signature

function string llEscapeURL( string url );