Topic
  • 17 replies
  • Latest Post - ‏2018-03-28T08:57:56Z by momasa
momasa
momasa
80 Posts

Pinned topic Datapower str:decode

‏2018-02-27T12:58:44Z |

 

Hello,

is 'iso-8859-1' supported in this extension function.

If yes, what is the correct encoding name

str:decode-uri('ABCÄÜÖ', 'iso-8859-1') returns an empty string.

We have also tried 'iso8859_1' or 'latin1'. Doesn't work.

 

Thanks and kind regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-27T13:42:34Z  

    Yes:
    https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com.ibm.dp.doc/decode-uri_exslt_stringmodule.html

    But then 'iso-8859-1' is the encoding of the URI, not the result of the function (that will always be UTF-8, theDataPower internal encoding).

    Hermann.

  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-27T13:48:26Z  
    • HermannSW
    • ‏2018-02-27T13:42:34Z

    Yes:
    https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com.ibm.dp.doc/decode-uri_exslt_stringmodule.html

    But then 'iso-8859-1' is the encoding of the URI, not the result of the function (that will always be UTF-8, theDataPower internal encoding).

    Hermann.

    Ok, thanks, but still:

    <xsl:text>TEST: </xsl:text><xsl:value-of select="str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1')" />

    returns an empty string. This should have a result?

    Regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-27T14:55:02Z  
    • momasa
    • ‏2018-02-27T13:48:26Z

    Ok, thanks, but still:

    <xsl:text>TEST: </xsl:text><xsl:value-of select="str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1')" />

    returns an empty string. This should have a result?

    Regards, Uli

    Ooops.

    I tried that and saw what you saw, empty string.

    Next I looked into DataPower firmware source code and found that only UTF-8 encoding is supported for both, str:encode-uri() and str:decode-uri() extension funtions.

    Returning an empty string is what the "spec" requires for encodings not supported, so returning empty string for your sample is correct:
    http://exslt.org/str/functions/encode-uri/str.encode-uri.html
    http://exslt.org/str/functions/decode-uri/str.decode-uri.html

     If the encoding is given as an empty string or is not supported, then an empty string is returned.


    I am surprised on this, and was not aware of this since I joined DataPower development back in 2007.

    I did query version control and found that the implementation of both functions was done in 7/2006 and is unchanged since then. 

     

    For your request for 'iso-8859-1' there might be a solution for you, depending on your use case:

    DataPower "Convert Query Params to XML"/"convert-htp" action does URL decoding for ISO-8859-1 only. I know that since I had to write (my only) technote on how to deal with UTF-8 encoded URIs back in 2009:
    http://www-01.ibm.com/support/docview.wss?uid=swg21412370


    <url> contains the original URL, the <arg> elements contain the decoded strings:

    1027💻  curl http://dp3-l3:2070/foobar?a=A%A3B
    <request><url>/foobar?a=A%A3B</url><base-url>/foobar</base-url><args src='url'>
    <arg name="a">A£B</arg></args></request>
    1028💻  
    


    Hermann.

    Updated on 2018-02-27T14:58:23Z at 2018-02-27T14:58:23Z by HermannSW
  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-27T15:11:30Z  
    • momasa
    • ‏2018-02-27T13:48:26Z

    Ok, thanks, but still:

    <xsl:text>TEST: </xsl:text><xsl:value-of select="str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1')" />

    returns an empty string. This should have a result?

    Regards, Uli

    Hello, thanks. Yes we know your article. But we need to process a POSTed form-URL-encoded body which is not covered by your technote. You cover URLs.

    For this it would be sufficient for us, if "iso-8859-1" was supported.

    (By the way why is there an encoding-Parameter in encode-/decode-uri functions when only 'utf-8' is allowed/supported?)

    Regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-27T15:58:55Z  
    • momasa
    • ‏2018-02-27T15:11:30Z

    Hello, thanks. Yes we know your article. But we need to process a POSTed form-URL-encoded body which is not covered by your technote. You cover URLs.

    For this it would be sufficient for us, if "iso-8859-1" was supported.

    (By the way why is there an encoding-Parameter in encode-/decode-uri functions when only 'utf-8' is allowed/supported?)

    Regards, Uli

    'ABCÄÜÖ' is not valid percent encopded URL, 'ABC%C4%DC%D6'  would be.

    So you want to be able to return 'ABCÄÜÖ' as from input 'ABC%C4%DC%D6' ?

  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-27T16:25:58Z  
    • HermannSW
    • ‏2018-02-27T15:58:55Z

    'ABCÄÜÖ' is not valid percent encopded URL, 'ABC%C4%DC%D6'  would be.

    So you want to be able to return 'ABCÄÜÖ' as from input 'ABC%C4%DC%D6' ?

    Yes, but that was just a bad example.

    Please could you check if datapower could Support iso-8859-1 in str:encode-/decode-uri functions. Thanks.

    We need it for our purposes.

     

    Regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-27T17:46:07Z  
    • momasa
    • ‏2018-02-27T16:25:58Z

    Yes, but that was just a bad example.

    Please could you check if datapower could Support iso-8859-1 in str:encode-/decode-uri functions. Thanks.

    We need it for our purposes.

     

    Regards, Uli

    Hi Uli,

    adding additional encodings to both extension functions requires design, implementation, testing and documentation.
    That is outside the scope of PMR process.

    Please create an ER on this:
    https://www.ibm.com/developerworks/rfe

    Here is a working XSLT function solution for you, stylesheet is attached as well:

    1068💻  coproc2 momasa.xsl <(echo '<i>ABC%c4%Dc%D6%c4</i>') http://dp3-l3:2223; echo
    ABCÄÜÖÄ
    1069💻  cat momasa.xsl 
    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
      xmlns:dp="http://www.datapower.com/extensions"
      xmlns:str="http://exslt.org/strings"
      xmlns:func="http://exslt.org/functions"
      xmlns:regexp="http://exslt.org/regular-expressions"
      extension-element-prefixes="dp"
    >
      <xsl:template match="/">
        <xsl:value-of select="func:decode-uri-8859-1(.)" />
      </xsl:template>
    
      <func:function name="func:decode-uri-8859-1">
        <xsl:param name="str"/>
    
        <func:result>
          <xsl:choose>
            <xsl:when test="not(substring-after($str, '%'))">
              <xsl:value-of select="$str"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:variable name="suf" select="substring-after($str, '%')"/>
    
              <xsl:variable name="srh"
                select="concat('%', substring($suf, 1, 2))"/>
              <xsl:variable name="srH"
                select="translate($srh, 'abcdef', 'ABCDEF')"/>
    
              <xsl:variable name="rep"
                select="regexp:replace($str, $srh, 'g', $lookup/map[@srh=$srH])"/>
    
              <xsl:value-of select="func:decode-uri-8859-1($rep)"/>
            </xsl:otherwise>
          </xsl:choose>
        </func:result>
      </func:function>
    
      <xsl:variable name="lookup">
        <map srh="%09">&#x09;</map>
        <map srh="%0A">&#x0A;</map>
        <map srh="%0D">&#x0D;</map>
        <map srh="%20">&#x20;</map>
        <map srh="%21">&#x21;</map>
        <map srh="%22">&#x22;</map>
        <map srh="%23">&#x23;</map>
        <map srh="%24">&#x24;</map>
        <map srh="%25">&#x25;</map>
        <map srh="%26">&#x26;</map>
        <map srh="%27">&#x27;</map>
        <map srh="%28">&#x28;</map>
        <map srh="%29">&#x29;</map>
        <map srh="%2A">&#x2A;</map>
        <map srh="%2B">&#x2B;</map>
        <map srh="%2C">&#x2C;</map>
        <map srh="%2D">&#x2D;</map>
        <map srh="%2E">&#x2E;</map>
        <map srh="%2F">&#x2F;</map>
        <map srh="%30">&#x30;</map>
        <map srh="%31">&#x31;</map>
        <map srh="%32">&#x32;</map>
        <map srh="%33">&#x33;</map>
        <map srh="%34">&#x34;</map>
        <map srh="%35">&#x35;</map>
        <map srh="%36">&#x36;</map>
        <map srh="%37">&#x37;</map>
        <map srh="%38">&#x38;</map>
        <map srh="%39">&#x39;</map>
        <map srh="%3A">&#x3A;</map>
        <map srh="%3B">&#x3B;</map>
        <map srh="%3C">&#x3C;</map>
        <map srh="%3D">&#x3D;</map>
        <map srh="%3E">&#x3E;</map>
        <map srh="%3F">&#x3F;</map>
        <map srh="%40">&#x40;</map>
        <map srh="%41">&#x41;</map>
        <map srh="%42">&#x42;</map>
        <map srh="%43">&#x43;</map>
        <map srh="%44">&#x44;</map>
        <map srh="%45">&#x45;</map>
        <map srh="%46">&#x46;</map>
        <map srh="%47">&#x47;</map>
        <map srh="%48">&#x48;</map>
        <map srh="%49">&#x49;</map>
        <map srh="%4A">&#x4A;</map>
        <map srh="%4B">&#x4B;</map>
        <map srh="%4C">&#x4C;</map>
        <map srh="%4D">&#x4D;</map>
        <map srh="%4E">&#x4E;</map>
        <map srh="%4F">&#x4F;</map>
        <map srh="%50">&#x50;</map>
        <map srh="%51">&#x51;</map>
        <map srh="%52">&#x52;</map>
        <map srh="%53">&#x53;</map>
        <map srh="%54">&#x54;</map>
        <map srh="%55">&#x55;</map>
        <map srh="%56">&#x56;</map>
        <map srh="%57">&#x57;</map>
        <map srh="%58">&#x58;</map>
        <map srh="%59">&#x59;</map>
        <map srh="%5A">&#x5A;</map>
        <map srh="%5B">&#x5B;</map>
        <map srh="%5C">&#x5C;</map>
        <map srh="%5D">&#x5D;</map>
        <map srh="%5E">&#x5E;</map>
        <map srh="%5F">&#x5F;</map>
        <map srh="%60">&#x60;</map>
        <map srh="%61">&#x61;</map>
        <map srh="%62">&#x62;</map>
        <map srh="%63">&#x63;</map>
        <map srh="%64">&#x64;</map>
        <map srh="%65">&#x65;</map>
        <map srh="%66">&#x66;</map>
        <map srh="%67">&#x67;</map>
        <map srh="%68">&#x68;</map>
        <map srh="%69">&#x69;</map>
        <map srh="%6A">&#x6A;</map>
        <map srh="%6B">&#x6B;</map>
        <map srh="%6C">&#x6C;</map>
        <map srh="%6D">&#x6D;</map>
        <map srh="%6E">&#x6E;</map>
        <map srh="%6F">&#x6F;</map>
        <map srh="%70">&#x70;</map>
        <map srh="%71">&#x71;</map>
        <map srh="%72">&#x72;</map>
        <map srh="%73">&#x73;</map>
        <map srh="%74">&#x74;</map>
        <map srh="%75">&#x75;</map>
        <map srh="%76">&#x76;</map>
        <map srh="%77">&#x77;</map>
        <map srh="%78">&#x78;</map>
        <map srh="%79">&#x79;</map>
        <map srh="%7A">&#x7A;</map>
        <map srh="%7B">&#x7B;</map>
        <map srh="%7C">&#x7C;</map>
        <map srh="%7D">&#x7D;</map>
        <map srh="%7E">&#x7E;</map>
        <map srh="%7F">&#x7F;</map>
        <map srh="%80">&#x80;</map>
        <map srh="%81">&#x81;</map>
        <map srh="%82">&#x82;</map>
        <map srh="%83">&#x83;</map>
        <map srh="%84">&#x84;</map>
        <map srh="%85">&#x85;</map>
        <map srh="%86">&#x86;</map>
        <map srh="%87">&#x87;</map>
        <map srh="%88">&#x88;</map>
        <map srh="%89">&#x89;</map>
        <map srh="%8A">&#x8A;</map>
        <map srh="%8B">&#x8B;</map>
        <map srh="%8C">&#x8C;</map>
        <map srh="%8D">&#x8D;</map>
        <map srh="%8E">&#x8E;</map>
        <map srh="%8F">&#x8F;</map>
        <map srh="%90">&#x90;</map>
        <map srh="%91">&#x91;</map>
        <map srh="%92">&#x92;</map>
        <map srh="%93">&#x93;</map>
        <map srh="%94">&#x94;</map>
        <map srh="%95">&#x95;</map>
        <map srh="%96">&#x96;</map>
        <map srh="%97">&#x97;</map>
        <map srh="%98">&#x98;</map>
        <map srh="%99">&#x99;</map>
        <map srh="%9A">&#x9A;</map>
        <map srh="%9B">&#x9B;</map>
        <map srh="%9C">&#x9C;</map>
        <map srh="%9D">&#x9D;</map>
        <map srh="%9E">&#x9E;</map>
        <map srh="%9F">&#x9F;</map>
        <map srh="%A0">&#xA0;</map>
        <map srh="%A1">&#xA1;</map>
        <map srh="%A2">&#xA2;</map>
        <map srh="%A3">&#xA3;</map>
        <map srh="%A4">&#xA4;</map>
        <map srh="%A5">&#xA5;</map>
        <map srh="%A6">&#xA6;</map>
        <map srh="%A7">&#xA7;</map>
        <map srh="%A8">&#xA8;</map>
        <map srh="%A9">&#xA9;</map>
        <map srh="%AA">&#xAA;</map>
        <map srh="%AB">&#xAB;</map>
        <map srh="%AC">&#xAC;</map>
        <map srh="%AD">&#xAD;</map>
        <map srh="%AE">&#xAE;</map>
        <map srh="%AF">&#xAF;</map>
        <map srh="%B0">&#xB0;</map>
        <map srh="%B1">&#xB1;</map>
        <map srh="%B2">&#xB2;</map>
        <map srh="%B3">&#xB3;</map>
        <map srh="%B4">&#xB4;</map>
        <map srh="%B5">&#xB5;</map>
        <map srh="%B6">&#xB6;</map>
        <map srh="%B7">&#xB7;</map>
        <map srh="%B8">&#xB8;</map>
        <map srh="%B9">&#xB9;</map>
        <map srh="%BA">&#xBA;</map>
        <map srh="%BB">&#xBB;</map>
        <map srh="%BC">&#xBC;</map>
        <map srh="%BD">&#xBD;</map>
        <map srh="%BE">&#xBE;</map>
        <map srh="%BF">&#xBF;</map>
        <map srh="%C0">&#xC0;</map>
        <map srh="%C1">&#xC1;</map>
        <map srh="%C2">&#xC2;</map>
        <map srh="%C3">&#xC3;</map>
        <map srh="%C4">&#xC4;</map>
        <map srh="%C5">&#xC5;</map>
        <map srh="%C6">&#xC6;</map>
        <map srh="%C7">&#xC7;</map>
        <map srh="%C8">&#xC8;</map>
        <map srh="%C9">&#xC9;</map>
        <map srh="%CA">&#xCA;</map>
        <map srh="%CB">&#xCB;</map>
        <map srh="%CC">&#xCC;</map>
        <map srh="%CD">&#xCD;</map>
        <map srh="%CE">&#xCE;</map>
        <map srh="%CF">&#xCF;</map>
        <map srh="%D0">&#xD0;</map>
        <map srh="%D1">&#xD1;</map>
        <map srh="%D2">&#xD2;</map>
        <map srh="%D3">&#xD3;</map>
        <map srh="%D4">&#xD4;</map>
        <map srh="%D5">&#xD5;</map>
        <map srh="%D6">&#xD6;</map>
        <map srh="%D7">&#xD7;</map>
        <map srh="%D8">&#xD8;</map>
        <map srh="%D9">&#xD9;</map>
        <map srh="%DA">&#xDA;</map>
        <map srh="%DB">&#xDB;</map>
        <map srh="%DC">&#xDC;</map>
        <map srh="%DD">&#xDD;</map>
        <map srh="%DE">&#xDE;</map>
        <map srh="%DF">&#xDF;</map>
        <map srh="%E0">&#xE0;</map>
        <map srh="%E1">&#xE1;</map>
        <map srh="%E2">&#xE2;</map>
        <map srh="%E3">&#xE3;</map>
        <map srh="%E4">&#xE4;</map>
        <map srh="%E5">&#xE5;</map>
        <map srh="%E6">&#xE6;</map>
        <map srh="%E7">&#xE7;</map>
        <map srh="%E8">&#xE8;</map>
        <map srh="%E9">&#xE9;</map>
        <map srh="%EA">&#xEA;</map>
        <map srh="%EB">&#xEB;</map>
        <map srh="%EC">&#xEC;</map>
        <map srh="%ED">&#xED;</map>
        <map srh="%EE">&#xEE;</map>
        <map srh="%EF">&#xEF;</map>
        <map srh="%F0">&#xF0;</map>
        <map srh="%F1">&#xF1;</map>
        <map srh="%F2">&#xF2;</map>
        <map srh="%F3">&#xF3;</map>
        <map srh="%F4">&#xF4;</map>
        <map srh="%F5">&#xF5;</map>
        <map srh="%F6">&#xF6;</map>
        <map srh="%F7">&#xF7;</map>
        <map srh="%F8">&#xF8;</map>
        <map srh="%F9">&#xF9;</map>
        <map srh="%FA">&#xFA;</map>
        <map srh="%FB">&#xFB;</map>
        <map srh="%FC">&#xFC;</map>
        <map srh="%FD">&#xFD;</map>
        <map srh="%FE">&#xFE;</map>
        <map srh="%FF">&#xFF;</map>
      </xsl:variable>
    
    </xsl:stylesheet>
    1070💻  
    

     

    Hermann.

    Attachments

    Updated on 2018-02-27T18:42:31Z at 2018-02-27T18:42:31Z by HermannSW
  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-28T08:15:10Z  
    • HermannSW
    • ‏2018-02-27T17:46:07Z

    Hi Uli,

    adding additional encodings to both extension functions requires design, implementation, testing and documentation.
    That is outside the scope of PMR process.

    Please create an ER on this:
    https://www.ibm.com/developerworks/rfe

    Here is a working XSLT function solution for you, stylesheet is attached as well:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">1068💻 coproc2 momasa.xsl <(echo '<i>ABC%c4%Dc%D6%c4</i>') http://dp3-l3:2223; echo ABCÄÜÖÄ 1069💻 cat momasa.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dp="http://www.datapower.com/extensions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:regexp="http://exslt.org/regular-expressions" extension-element-prefixes="dp" > <xsl:template match="/"> <xsl:value-of select="func:decode-uri-8859-1(.)" /> </xsl:template> <func:function name="func:decode-uri-8859-1"> <xsl:param name="str"/> <func:result> <xsl:choose> <xsl:when test="not(substring-after($str, '%'))"> <xsl:value-of select="$str"/> </xsl:when> <xsl:otherwise> <xsl:variable name="suf" select="substring-after($str, '%')"/> <xsl:variable name="srh" select="concat('%', substring($suf, 1, 2))"/> <xsl:variable name="srH" select="translate($srh, 'abcdef', 'ABCDEF')"/> <xsl:variable name="rep" select="regexp:replace($str, $srh, 'g', $lookup/map[@srh=$srH])"/> <xsl:value-of select="func:decode-uri-8859-1($rep)"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function> <xsl:variable name="lookup"> <map srh="%09">&#x09;</map> <map srh="%0A">&#x0A;</map> <map srh="%0D">&#x0D;</map> <map srh="%20">&#x20;</map> <map srh="%21">&#x21;</map> <map srh="%22">&#x22;</map> <map srh="%23">&#x23;</map> <map srh="%24">&#x24;</map> <map srh="%25">&#x25;</map> <map srh="%26">&#x26;</map> <map srh="%27">&#x27;</map> <map srh="%28">&#x28;</map> <map srh="%29">&#x29;</map> <map srh="%2A">&#x2A;</map> <map srh="%2B">&#x2B;</map> <map srh="%2C">&#x2C;</map> <map srh="%2D">&#x2D;</map> <map srh="%2E">&#x2E;</map> <map srh="%2F">&#x2F;</map> <map srh="%30">&#x30;</map> <map srh="%31">&#x31;</map> <map srh="%32">&#x32;</map> <map srh="%33">&#x33;</map> <map srh="%34">&#x34;</map> <map srh="%35">&#x35;</map> <map srh="%36">&#x36;</map> <map srh="%37">&#x37;</map> <map srh="%38">&#x38;</map> <map srh="%39">&#x39;</map> <map srh="%3A">&#x3A;</map> <map srh="%3B">&#x3B;</map> <map srh="%3C">&#x3C;</map> <map srh="%3D">&#x3D;</map> <map srh="%3E">&#x3E;</map> <map srh="%3F">&#x3F;</map> <map srh="%40">&#x40;</map> <map srh="%41">&#x41;</map> <map srh="%42">&#x42;</map> <map srh="%43">&#x43;</map> <map srh="%44">&#x44;</map> <map srh="%45">&#x45;</map> <map srh="%46">&#x46;</map> <map srh="%47">&#x47;</map> <map srh="%48">&#x48;</map> <map srh="%49">&#x49;</map> <map srh="%4A">&#x4A;</map> <map srh="%4B">&#x4B;</map> <map srh="%4C">&#x4C;</map> <map srh="%4D">&#x4D;</map> <map srh="%4E">&#x4E;</map> <map srh="%4F">&#x4F;</map> <map srh="%50">&#x50;</map> <map srh="%51">&#x51;</map> <map srh="%52">&#x52;</map> <map srh="%53">&#x53;</map> <map srh="%54">&#x54;</map> <map srh="%55">&#x55;</map> <map srh="%56">&#x56;</map> <map srh="%57">&#x57;</map> <map srh="%58">&#x58;</map> <map srh="%59">&#x59;</map> <map srh="%5A">&#x5A;</map> <map srh="%5B">&#x5B;</map> <map srh="%5C">&#x5C;</map> <map srh="%5D">&#x5D;</map> <map srh="%5E">&#x5E;</map> <map srh="%5F">&#x5F;</map> <map srh="%60">&#x60;</map> <map srh="%61">&#x61;</map> <map srh="%62">&#x62;</map> <map srh="%63">&#x63;</map> <map srh="%64">&#x64;</map> <map srh="%65">&#x65;</map> <map srh="%66">&#x66;</map> <map srh="%67">&#x67;</map> <map srh="%68">&#x68;</map> <map srh="%69">&#x69;</map> <map srh="%6A">&#x6A;</map> <map srh="%6B">&#x6B;</map> <map srh="%6C">&#x6C;</map> <map srh="%6D">&#x6D;</map> <map srh="%6E">&#x6E;</map> <map srh="%6F">&#x6F;</map> <map srh="%70">&#x70;</map> <map srh="%71">&#x71;</map> <map srh="%72">&#x72;</map> <map srh="%73">&#x73;</map> <map srh="%74">&#x74;</map> <map srh="%75">&#x75;</map> <map srh="%76">&#x76;</map> <map srh="%77">&#x77;</map> <map srh="%78">&#x78;</map> <map srh="%79">&#x79;</map> <map srh="%7A">&#x7A;</map> <map srh="%7B">&#x7B;</map> <map srh="%7C">&#x7C;</map> <map srh="%7D">&#x7D;</map> <map srh="%7E">&#x7E;</map> <map srh="%7F">&#x7F;</map> <map srh="%80">&#x80;</map> <map srh="%81">&#x81;</map> <map srh="%82">&#x82;</map> <map srh="%83">&#x83;</map> <map srh="%84">&#x84;</map> <map srh="%85">&#x85;</map> <map srh="%86">&#x86;</map> <map srh="%87">&#x87;</map> <map srh="%88">&#x88;</map> <map srh="%89">&#x89;</map> <map srh="%8A">&#x8A;</map> <map srh="%8B">&#x8B;</map> <map srh="%8C">&#x8C;</map> <map srh="%8D">&#x8D;</map> <map srh="%8E">&#x8E;</map> <map srh="%8F">&#x8F;</map> <map srh="%90">&#x90;</map> <map srh="%91">&#x91;</map> <map srh="%92">&#x92;</map> <map srh="%93">&#x93;</map> <map srh="%94">&#x94;</map> <map srh="%95">&#x95;</map> <map srh="%96">&#x96;</map> <map srh="%97">&#x97;</map> <map srh="%98">&#x98;</map> <map srh="%99">&#x99;</map> <map srh="%9A">&#x9A;</map> <map srh="%9B">&#x9B;</map> <map srh="%9C">&#x9C;</map> <map srh="%9D">&#x9D;</map> <map srh="%9E">&#x9E;</map> <map srh="%9F">&#x9F;</map> <map srh="%A0">&#xA0;</map> <map srh="%A1">&#xA1;</map> <map srh="%A2">&#xA2;</map> <map srh="%A3">&#xA3;</map> <map srh="%A4">&#xA4;</map> <map srh="%A5">&#xA5;</map> <map srh="%A6">&#xA6;</map> <map srh="%A7">&#xA7;</map> <map srh="%A8">&#xA8;</map> <map srh="%A9">&#xA9;</map> <map srh="%AA">&#xAA;</map> <map srh="%AB">&#xAB;</map> <map srh="%AC">&#xAC;</map> <map srh="%AD">&#xAD;</map> <map srh="%AE">&#xAE;</map> <map srh="%AF">&#xAF;</map> <map srh="%B0">&#xB0;</map> <map srh="%B1">&#xB1;</map> <map srh="%B2">&#xB2;</map> <map srh="%B3">&#xB3;</map> <map srh="%B4">&#xB4;</map> <map srh="%B5">&#xB5;</map> <map srh="%B6">&#xB6;</map> <map srh="%B7">&#xB7;</map> <map srh="%B8">&#xB8;</map> <map srh="%B9">&#xB9;</map> <map srh="%BA">&#xBA;</map> <map srh="%BB">&#xBB;</map> <map srh="%BC">&#xBC;</map> <map srh="%BD">&#xBD;</map> <map srh="%BE">&#xBE;</map> <map srh="%BF">&#xBF;</map> <map srh="%C0">&#xC0;</map> <map srh="%C1">&#xC1;</map> <map srh="%C2">&#xC2;</map> <map srh="%C3">&#xC3;</map> <map srh="%C4">&#xC4;</map> <map srh="%C5">&#xC5;</map> <map srh="%C6">&#xC6;</map> <map srh="%C7">&#xC7;</map> <map srh="%C8">&#xC8;</map> <map srh="%C9">&#xC9;</map> <map srh="%CA">&#xCA;</map> <map srh="%CB">&#xCB;</map> <map srh="%CC">&#xCC;</map> <map srh="%CD">&#xCD;</map> <map srh="%CE">&#xCE;</map> <map srh="%CF">&#xCF;</map> <map srh="%D0">&#xD0;</map> <map srh="%D1">&#xD1;</map> <map srh="%D2">&#xD2;</map> <map srh="%D3">&#xD3;</map> <map srh="%D4">&#xD4;</map> <map srh="%D5">&#xD5;</map> <map srh="%D6">&#xD6;</map> <map srh="%D7">&#xD7;</map> <map srh="%D8">&#xD8;</map> <map srh="%D9">&#xD9;</map> <map srh="%DA">&#xDA;</map> <map srh="%DB">&#xDB;</map> <map srh="%DC">&#xDC;</map> <map srh="%DD">&#xDD;</map> <map srh="%DE">&#xDE;</map> <map srh="%DF">&#xDF;</map> <map srh="%E0">&#xE0;</map> <map srh="%E1">&#xE1;</map> <map srh="%E2">&#xE2;</map> <map srh="%E3">&#xE3;</map> <map srh="%E4">&#xE4;</map> <map srh="%E5">&#xE5;</map> <map srh="%E6">&#xE6;</map> <map srh="%E7">&#xE7;</map> <map srh="%E8">&#xE8;</map> <map srh="%E9">&#xE9;</map> <map srh="%EA">&#xEA;</map> <map srh="%EB">&#xEB;</map> <map srh="%EC">&#xEC;</map> <map srh="%ED">&#xED;</map> <map srh="%EE">&#xEE;</map> <map srh="%EF">&#xEF;</map> <map srh="%F0">&#xF0;</map> <map srh="%F1">&#xF1;</map> <map srh="%F2">&#xF2;</map> <map srh="%F3">&#xF3;</map> <map srh="%F4">&#xF4;</map> <map srh="%F5">&#xF5;</map> <map srh="%F6">&#xF6;</map> <map srh="%F7">&#xF7;</map> <map srh="%F8">&#xF8;</map> <map srh="%F9">&#xF9;</map> <map srh="%FA">&#xFA;</map> <map srh="%FB">&#xFB;</map> <map srh="%FC">&#xFC;</map> <map srh="%FD">&#xFD;</map> <map srh="%FE">&#xFE;</map> <map srh="%FF">&#xFF;</map> </xsl:variable> </xsl:stylesheet> 1070💻 </pre>

     

    Hermann.

    Hello, thanks Hermann.

    do you have a workaround for Encoding with "iso", too?

    Thanks

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-28T08:48:09Z  
    • momasa
    • ‏2018-02-28T08:15:10Z

    Hello, thanks Hermann.

    do you have a workaround for Encoding with "iso", too?

    Thanks

    Hi Uli,

    the function I provided is for iso-8859-1, please rename "func:decode-uri-8859-1" to "func:decode-uri-iso-8859-1".

    Hermann.

    Updated on 2018-02-28T08:49:23Z at 2018-02-28T08:49:23Z by HermannSW
  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-28T12:15:23Z  
    • HermannSW
    • ‏2018-02-28T08:48:09Z

    Hi Uli,

    the function I provided is for iso-8859-1, please rename "func:decode-uri-8859-1" to "func:decode-uri-iso-8859-1".

    Hermann.

    Hello, your previous function is for decoding.

    We look for an encoding function.

     

    Thanks and kind regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-28T13:13:22Z  
    • momasa
    • ‏2018-02-28T12:15:23Z

    Hello, your previous function is for decoding.

    We look for an encoding function.

     

    Thanks and kind regards, Uli

    There is no way to have a ISO-8859-1 string in XSLT since DataPower internal encoding is UTF-8.

    Please describe what you want to do.

    How do you want to pass ISO-8859-1 string in "str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1')"?

    Hermann.

  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-02-28T14:08:59Z  
    • HermannSW
    • ‏2018-02-28T13:13:22Z

    There is no way to have a ISO-8859-1 string in XSLT since DataPower internal encoding is UTF-8.

    Please describe what you want to do.

    How do you want to pass ISO-8859-1 string in "str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1')"?

    Hermann.

    Hello,

    yes, str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1') is the requested function.

    We receive such strings (e.g. ABCÄÜÖ) from POSTs sent by some clients.

    Thanks, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-02-28T16:01:14Z  
    • momasa
    • ‏2018-02-28T14:08:59Z

    Hello,

    yes, str:encode-uri('ABCÄÜÖ', false(), 'iso-8859-1') is the requested function.

    We receive such strings (e.g. ABCÄÜÖ) from POSTs sent by some clients.

    Thanks, Uli

    Best solution will be to call out to GatewayScript:

    1058💻  coproc2 y.js <(echo -n "<a>Hölle</a>") http://dp3-l3:2227; echo
    72,246,108,108,101,
    1058💻  
    1058💻  cat y.js 
    session.input.readAsXML(function(error, xml) { throwIf(error);
      var res="", str = xml.item(0).firstChild.nodeValue;
      var i;
    
      for(i=0; i<str.length; ++i) {
        res=res+str.codePointAt(i)+",";
      }
    
      session.output.write(res);
    });
    
    function throwIf(error) { if (error)  throw error; }
    1059💻  
    


    So which characters from unicode point range 0-255 (Latin1 or iso-8859-1) do you want to percent escape, and which to stay as is?

    What do you want to happen with a unicode codepoint >255?

    Hermann.

    Updated on 2018-02-28T16:02:42Z at 2018-02-28T16:02:42Z by HermannSW
  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-03-01T09:25:20Z  
    • HermannSW
    • ‏2018-02-28T16:01:14Z

    Best solution will be to call out to GatewayScript:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">1058💻 coproc2 y.js <(echo -n "<a>Hölle</a>") http://dp3-l3:2227; echo 72,246,108,108,101, 1058💻 1058💻 cat y.js session.input.readAsXML(function(error, xml) { throwIf(error); var res="", str = xml.item(0).firstChild.nodeValue; var i; for(i=0; i<str.length; ++i) { res=res+str.codePointAt(i)+","; } session.output.write(res); }); function throwIf(error) { if (error) throw error; } 1059💻 </pre>


    So which characters from unicode point range 0-255 (Latin1 or iso-8859-1) do you want to percent escape, and which to stay as is?

    What do you want to happen with a unicode codepoint >255?

    Hermann.

    Hello Hermann, thanks for your many inputs.

    we need to handle 7F-FF. We will try your workaround next time.

    Kind regards, Uli

  • HermannSW
    HermannSW
    8544 Posts

    Re: Datapower str:decode

    ‏2018-03-01T12:24:44Z  
    • momasa
    • ‏2018-03-01T09:25:20Z

    Hello Hermann, thanks for your many inputs.

    we need to handle 7F-FF. We will try your workaround next time.

    Kind regards, Uli

    Hi Uli,

    here is working "std:encode-uri()" implementation for iso-8859-1 for you:

    1024💻  coproc2 momasa.xsl <(echo -n "<a>Hölle</a>") http://dp3-l3:2223; echo
    <?xml version="1.0" encoding="UTF-8"?>
    <gatewayscript><errorcode>0x00000000</errorcode><result>H%f6lle</result></gatewayscript>
    1025💻  
    


    This is the GatewayScript doing percent encoding according your requirement:

    1028💻  cat momasa.js 
    session.input.readAsXML(function(error, xml) { throwIf(error);
      var res="", str = xml.item(0).firstChild.nodeValue;
      var i, cp;
    
      for(i=0; i<str.length; ++i) {
        cp = str.codePointAt(i);
        res = res + ((cp < 0x7F) ? str.charAt(i) : "%"+(cp).toString(16));
      }
    
      session.output.write(res);
    });
    
    function throwIf(error) { if (error)  throw error; }
    1029💻  
    

     

    And here is how to call that from within XSLT:

    1029💻  cat momasa.xsl 
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:template match="/">
        <xsl:copy-of select="dp:gatewayscript('local:///momasa.js', .)"/>
      </xsl:template>
      
    </xsl:stylesheet>
    1030💻  
    

     

    For iso-8859-1 uri-decode please use "func:decode-uri-iso-8859-1" function shown before.

    Please let me know in case anything is missing.

     

    Hermann.

    Attachments

    Updated on 2018-03-01T12:28:20Z at 2018-03-01T12:28:20Z by HermannSW
  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-03-01T12:34:26Z  
    • HermannSW
    • ‏2018-03-01T12:24:44Z

    Hi Uli,

    here is working "std:encode-uri()" implementation for iso-8859-1 for you:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">1024💻 coproc2 momasa.xsl <(echo -n "<a>Hölle</a>") http://dp3-l3:2223; echo <?xml version="1.0" encoding="UTF-8"?> <gatewayscript><errorcode>0x00000000</errorcode><result>H%f6lle</result></gatewayscript> 1025💻 </pre>


    This is the GatewayScript doing percent encoding according your requirement:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">1028💻 cat momasa.js session.input.readAsXML(function(error, xml) { throwIf(error); var res="", str = xml.item(0).firstChild.nodeValue; var i, cp; for(i=0; i<str.length; ++i) { cp = str.codePointAt(i); res = res + ((cp < 0x7F) ? str.charAt(i) : "%"+(cp).toString(16)); } session.output.write(res); }); function throwIf(error) { if (error) throw error; } 1029💻 </pre>

     

    And here is how to call that from within XSLT:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">1029💻 cat momasa.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" > <xsl:template match="/"> <xsl:copy-of select="dp:gatewayscript('local:///momasa.js', .)"/> </xsl:template> </xsl:stylesheet> 1030💻 </pre>

     

    For iso-8859-1 uri-decode please use "func:decode-uri-iso-8859-1" function shown before.

    Please let me know in case anything is missing.

     

    Hermann.

    Thanks a lot once more ...

    We will try it later.

    Regards, Uli

  • momasa
    momasa
    80 Posts

    Re: Datapower str:decode

    ‏2018-03-28T08:57:56Z  
    • momasa
    • ‏2018-03-01T12:34:26Z

    Thanks a lot once more ...

    We will try it later.

    Regards, Uli

    Hello Hermann,

    your example gave us some good hints to fit our needs. Thanks a lot.

    Here is our solution. (If anybody else gets into this situation ....)

     

    custum xslt:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions"
    xmlns:str="http://exslt.org/strings"
    xmlns:regexp="http://exslt.org/regular-expressions"
    exclude-result-prefixes="dp str dpconfig"
    extension-element-prefixes="dp str"
    >
      <xsl:output method="xml" />
      <xsl:template match="/request">
     <request>
      <xsl:apply-templates select='./*' />
     </request>
      </xsl:template>
      
      <xsl:template match="//arg[@name='j_username']">
      <xsl:variable name="usernameOrig"><xsl:value-of select="."/></xsl:variable>
      <xsl:variable name="usernameAdapted"><xsl:copy-of select="dp:gatewayscript('local://xslt/ConvertChars.js', .)"/></xsl:variable>
      <arg name="j_username"><xsl:value-of select="$usernameAdapted//result" /></arg>
      </xsl:template>
      
      <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()" />
            </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    

     

    called gateway script:

    session.input.readAsXML(function(error, xml) { throwIf(error);
      var res="", str = xml.item(0).firstChild.nodeValue;
      var i, cp, c;
      i=1;
      res = decodeURIComponent(recodeURL(str));
      session.output.write(res);
    });
    
    function recodeURL(str) {
     var i;
     var pattern = /([^\x00-\x7F]+)/ ;
     var match;
     while (pattern.test(str)) {
      match = pattern.exec(str)
      var numberString = match[1];
      var hexNumber = ""
      for (i=0; i<numberString.length; i++) {
       var c = numberString.charCodeAt(i);
       hexNumber = hexNumber + "%" + c.toString(16);
      }   
      str = str.replace(/([^\x00-\x7F]+)/, hexNumber);
     }
     return str;
    }
    
    function throwIf(error) { if (error)  throw error; }
    

    Regards, Uli