2

We have a scenario where a page submits multiple fields with the same name. To workaround the default approach of CF to put these into a comma-delimited string, without changing application-wide, we access field values in certain places as an array using getPageContext().getRequest().getParameterValues("#fieldname#").

The problem we are experiencing is that unicode characters submitted are being corrupted. For example El celular que compré está averiado in a field array comes back as the string El celular que compré está averiado. If I dump getHTTPRequestData() I can see the properly url encoded El+celular+que+compr%C3%A9+est%C3%A1+averiado is sent to the server.

Is the java string not being handled by CF correctly? Anyway to resolve this issue on a non-application-wide basis other than parsing getHTTPRequestData().content which we really don't want to do?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Dan Roberts
  • 4,664
  • 3
  • 34
  • 43

1 Answers1

2

The reason will be because your webserver is not using utf-8 internally for its encoding of parameters. You don't get to see this normally when accessing variables by the url scope, because CF has already converted them for you, however you can see this difference when looking at cgi.query_string or at getPageContext().getRequest().getParameterValues(...)

In your case it looks like you're seeing windows-1252 encoding. I had a similar issue around IIS7.5 - IIS8. Assuming you can't or don't want to risk trying to change your webserver configuration, this workaround should work for you:

webserverEncodedString = getPageContext().getRequest().getParameterValues(fieldname);
binaryValue = CharsetDecode(webserverEncodedString, "windows-1252");
utf8EncodedString = CharsetEncode(binaryValue, "utf-8");
Sev Roberts
  • 1,295
  • 6
  • 7
  • I actually came up with this resolution yesterday. Why it was happening I wasn't sure. Will check out the webserver's encoding though. – Dan Roberts Mar 03 '21 at 20:08
  • I wrote this in the comments against my code several years ago - it was on a Win 2008 R2 / IIS7.5 box: Inspiration comes from using https://stackoverflow.com/questions/39924847/convert-string-to-utf-8-unicode-in-coldfusion as a solution for https://stackoverflow.com/questions/2764446/problem-using-unicode-in-urls-with-cgi-path-info-in-coldfusion -alternative MS Hotfix: https://support.microsoft.com/en-us/topic/fix-a-php-application-that-depends-on-the-request-uri-server-variable-may-fail-when-a-request-whose-url-contains-utf-8-characters-is-sent-to-iis-7-5-a3055458-c109-1298-c704-30f0453a7bcb – Sev Roberts Mar 03 '21 at 22:06
  • I'm not sure at what point the utf-8 server variables option became a standard feature in IIS. I don't remember having to patch later servers. – Sev Roberts Mar 03 '21 at 22:09