Skip to content

Not processing "\u" characters in JSON String correctly with 4bytes unicode.

Original Reporter info from Mantis: parcel
  • Reporter name: Do-wan Kim

Description:

Json \u character conversion doesn't work correctly with 4bytes unicode.

work
json 2 | 2 | 2 | 2 | 2 -> unicode 2 | 2 | 2 | 2 | 2

fail
json 2 | 4 | 2 | 2 | 2 -> unicode 2 | 2 | 2 | 2

Steps to reproduce:

procedure TForm1.Button1Click(Sender: TObject);
var
    str : String;
    u : UnicodeString;
    json : TJsonObject;
    l : Integer;
begin
    str := '{"name":"\u95e8\ud867\ude3d\u88ab\u8111\u5b50\u6324\u574f\u4e86"}';
    json := GetJson(str) as TJsonObject;

    u:=UTF8Decode(json.Get('name',''));
    l:=Length(u);
    json.Free;

    if l<>9 then
      ShowMessage(Format('%s %d',[u,l]))
    else
    ShowMessage('ok');
end; 

Mantis conversion info:

  • Mantis ID: 38624
  • Build: 48965
  • Version: 3.3.1
  • Fixed in version: 3.3.1
  • Fixed in revision: 48980 (#5e913147)
  • Target version: 4.0.0
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information