I am calling my Delphi-RO Server from a JavaScript client via JSONMessage. I always use WideString for my string-types. It all worked perfect under 9.1.99.1273. But since I updated to 9.2.101.1295 I get a Encoding Exception in my server.
This happens in this case:
In my JS-Client I have a form for entering some data. If I type unicode characters like “€” I get a EEncodingError Exception after posting this to the server. This happens only after updating to the new version! Previous works.
I also tested the current alpha release - same issue.
The German Exception message is:
“Exception-Klasse EEncodingError mit Meldung ‘Keine Zuordnung für Unicode-Zeichen in der Multibyte-Zielcodeseite vorhanden’.”
The error seems to happen in:
TROJSONValue.LoadFromStream
at this line: w := UTF8BytesToString(@s[i], Length(s)-i);
This goes into: System.SysUtils -> TEncoding.GetString
I changed nothing from the previous ROSDK Version. I am using Delphi Berlin.
This is very urgent for me. Currently I am not able to switch to the new RO-Version / Delphi Tokyo.
this bug is reproduced only with Indy-based servers - they return request only as string and don’t as binary data.
as a result, UTF8 decoding was broken.
as a workaround, you can use others HTTP servers or use this fix for uROIndyHTTPServer.pas:
procedure TROIndyHTTPServer.InternalServerCommandGet(AThread: TIdThreadClass;
RequestInfo: TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
var
{$IFDEF UNICODE} k: TBytes; {$ENDIF} //added
..
{$IFDEF UNICODE} // this code block was added
aRequestStream := TROBinaryMemoryStream.Create();
if reqdata <> '' then begin
k := BytesOf(reqdata);
aRequestStream.Write(k[0],Length(k));
aRequestStream.Position := 0;
end;
{$ELSE}
aRequestStream := TROBinaryMemoryStream.Create(reqdata); // existing line
{$ENDIF}