$Web URL Decode and $Web URL Decode Lstr: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 5: Line 5:


==Syntax==
==Syntax==
<p class="syntax"><section begin="syntax" /> %OUT = $Web_URL_Decode( input_string )
<p class="syntax"><section begin="syntax" />%OUT = $Web_URL_Decode( input_string )
<section end="syntax" /></p>
<section end="syntax" /></p>



Revision as of 22:28, 24 October 2012

<section begin="desc" /> Do web URL decoding<section end="desc" />

$Web_URL_Decode and $Web_URL_Decode_Lstr decode strings encoded in the URL "% hex hex" format into unencoded strings. These functions were introduced in Sirius Mods Version 6.8. Strings in URL encoded format are generally found in URLs and form parameters, though the $WEB_URL and $WEB_FORM functions automatically decode these strings.

Syntax

<section begin="syntax" />%OUT = $Web_URL_Decode( input_string ) <section end="syntax" />

$Web_URL_Decode takes a single string argument and returns that string with special characters encoded using the URL "% hex hex" format. $Web_URL_Decode_LSTR is identical to $Web_URL_Decode with the (hopefully obvious) exception that it is longstring capable. That is, it can take a longstring input and produce the appropriate longstring output.

The only parameter is the input string to be decoded. If this string is omitted, a null string is returned.

$Web_URL_Decode and $Web_URL_Decode_Lstr provide the inverse functionality to $Web_URL_Encode and $Web_URL_Encode_Lstr. That is, instead of converting a string to the EBCDIC representation of its URL encoding, they convert an EBCDIC representation of a URL encoding of a string to that string. URL encoding and then decoding a string should produce the original input string, with the exception that $Web_URL_Encode, because it is non-longstring capable, can truncate its result.

$Web_URL_Decode and $Web_URL_Decode_Lstr are particularly useful in processing form fields when using the RAWINPUTONLY form processing (). For example, the form fields for a post to a URL where RAWINPUTONLY is in effect can be loaded into a Stringlist as follows:

%formParms is object stringList ... %formParms = new %formParms:parseLines($Web_Input_Content('TEXT'), ' &')

This produces a Stringlist that contains items of the format fieldname=value. Assuming that none of the form field names have been URL encoded by the browser (a reasonable assumption for most Latin character field names), this Stringlist is in a format that can be readily searched. For example, the following code locates the field named OrderNumber:

%itemNum = %formParms:locate('OrderNumber=', , 1, 12)

Now, because there is no way to ensure that the end-user did not put special characters into the value for field OrderNumber, it is necessary to URL-decode the found value:

if %itemNum then %order = $Lstr_Substr(%formParms:item(%itemNum), 13) %order = $web_url_decode_lstr(%order)

Before Sirius Mods Version 6.8 one would have to hope that the form field did not contain any URL encoded data, or would have to write one's own URL decoding function.