[SOLVED] Empty string returned from $decode("URL", str)

Author: richard.gill@agfa.com (richard.gill)

Hello all I'm handling the query string from a web context, and having issues with the URL encoding. I have in the URL this QS:


  I get the QUERY_STRING item (of the SERVERVARIABLES item of $webinfo("WEBSERVERCONTEXT")) and want to use it from my code. All works seamlessly, unless the QS is URL encoded :


  In this case I want the decoded characters. So I use the $decode function with "URL", and all works perfectly again :

qs = $encode("USTRING", $decode("URL", qs))

  But then passing a non URL encoded string to $decode makes it return an empty string! How can that be managed?   Kind Regards, Richard


  1. Hello Richard, In case a string is not URL encoded then $decode("URL") will return the Proc error -1789 ("Source is invalid URL format") and the return value will be empty. In the above mentioned Proc statement the Proc error of $decode("URL") will be overwritten by the Proc error returned by $encode("USTRING"), which in this case should be -1781 ("Source not found."). Would it be possible to add a check like (e.g.):

    if ($decode(“URL”, qs) != "")   qs = $encode(“USTRING”, $decode(“URL”, qs)) endif

    Hope this helps. Kind regards, Daniel

    Author: diseli (daniel.iseli@uniface.com)
  2. Hello Daniel Yes, I finally found a workaround to make the code as short and fast as possible:

    qs = $encode("USTRING", $decode("URL", qs1)) if (qs == "") qs = qs1 endif

      Thank you for your support. Kind regards, Richard

    Author: richard.gill (richard.gill@agfa.com)
  3. Hello Richard, Thanks for the info and you are welcome. Kind regards, Daniel

    Author: diseli (daniel.iseli@uniface.com)