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

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
Line 1: Line 1:
{{DISPLAYTITLE:$Web_URL_Decode and $Web_URL_Decode_Lstr}}
{{DISPLAYTITLE:$Web_URL_Decode and $Web_URL_Decode_Lstr}}
<span class="pageSubtitle"><section begin="desc" />and $Web_URL_Decode_Lstr: Do web URL decoding<section end="desc" /></span>
<span class="pageSubtitle"><section begin="desc" />: Do web URL decoding<section end="desc" /></span>


$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.


$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==
==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>


$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.  
$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.  
Line 18: Line 16:
$Web_URL_Decode and $Web_URL_Decode_Lstr are particularly useful in processing form fields when using the RAWINPUTONLY form processing ().
$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:
For example, the form fields for a post to a URL where RAWINPUTONLY is in effect can be loaded into a Stringlist as follows:
<p class="code"> %formParms is object stringList
<p class="code"> %formParms is object stringList
  ...
  ...
Line 23: Line 22:
  %formParms:parseLines($Web_Input_Content('TEXT'), ' &')
  %formParms:parseLines($Web_Input_Content('TEXT'), ' &')
</p>
</p>
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.
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 <tt>OrderNumber</tt>:
For example, the following code locates the field named <tt>OrderNumber</tt>:
<p class="code"> %itemNum = %formParms:locate('OrderNumber=', , 1, 12)
<p class="code"> %itemNum = %formParms:locate('OrderNumber=', , 1, 12)
</p>
</p>


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:
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:
<p class="code"> if %itemNum then
<p class="code"> if %itemNum then
  %order = $Lstr_Substr(%formParms:item(%itemNum), 13)
  %order = $Lstr_Substr(%formParms:item(%itemNum), 13)
  %order = $web_url_decode_lstr(%order)
  %order = $web_url_decode_lstr(%order)
</p>
</p>
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.
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.


[[Category:Janus Web Server $functions|$Web_URL_Decode and $Web_URL_Decode_Lstr]]
[[Category:Janus Web Server $functions|$Web_URL_Decode and $Web_URL_Decode_Lstr]]

Revision as of 15:43, 23 February 2011

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