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

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(13 intermediate revisions by 3 users not shown)
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" /> Do web URL decoding<section end="desc" /></span>
<span class="pageSubtitle"> Do web URL decoding</span>


<var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> 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.
<var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> decode strings encoded in the URL "% hex hex" format into unencoded strings. Strings in URL encoded format are generally found in URLs and form parameters, though the <var>$Web_URL</var> and <var>$Web_Form</var> functions automatically decode these strings.


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


<var>$Web_URL_Decode</var> takes a single string argument and returns that string with special characters encoded using the URL "% hex hex" format. <var>$Web_URL_Decode_LSTR</var> 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.  
<var>$Web_URL_Decode</var> takes a single string argument and returns that string with special characters encoded using the URL "% hex hex" format.  


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


<var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> provide the inverse functionality to <var>$Web_URL_Encode</var> and <var>$Web_URL_Encode_Lstr</var>. 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.  
==Usage notes==
<ul>
<li><var>$Web_URL_Decode_Lstr</var> is identical to <var>$Web_URL_Decode</var> with the exception that it is [[Longstrings|Longstring]] capable. That is, it can take a longstring input and produce the appropriate longstring output.  


<var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> are particularly useful in processing form fields when using the RAWINPUTONLY form processing ().
<li><var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> provide the inverse functionality to <var>$Web_URL_Encode</var> and <var>$Web_URL_Encode_Lstr</var>. 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 <var>$Web_URL_Encode</var>, because it is non-longstring capable, can truncate its result.
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
<li><var>$Web_URL_Decode</var> and <var>$Web_URL_Decode_Lstr</var> are particularly useful in processing form fields when using the <var>[[RAWINPUTONLY (JANUS DEFINE parameter)|RAWINPUTONLY]]</var> form processing.
For example, the form fields for a post to a URL where RAWINPUTONLY is in effect can be loaded into a <var>Stringlist</var> as follows:
<p class="code">%formParms is object stringList
  ...
  ...
%formParms = new
%formParms = new
%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 <var>Stringlist</var> 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 <code>OrderNumber</code>:


<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 <code>OrderNumber</code>, 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 this function was introduced, you 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.
</ul>


[[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]]

Latest revision as of 01:13, 16 April 2013

Do web URL decoding

$Web_URL_Decode and $Web_URL_Decode_Lstr decode strings encoded in the URL "% hex hex" format into unencoded strings. 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

%out = $Web_URL_Decode( input_string )

$Web_URL_Decode takes a single string argument and returns that string with special characters encoded using the URL "% hex hex" format.

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

Usage notes

  • $Web_URL_Decode_Lstr is identical to $Web_URL_Decode with the exception that it is Longstring capable. That is, it can take a longstring input and produce the appropriate longstring output.
  • $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 this function was introduced, you 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.