Skip to content

A demo project for Lazarus to show the parser bug of "fpjson" unit of Free Pascal.

Notifications You must be signed in to change notification settings

shenmin/fpjson-bug-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

fpjson-bug-demo


fpjson is the unit implements JSON support for Free Pascal. But it has a bug for processing "\u" characters in JSON String.

This is a demo (Lazarus) project to show the bug. The project is built with Lazarus 2.0.12 with Free Pascal 3.2.0.

It uses fpjson and other two open-source pascal JSON parsers (LkJson and JsonTools) to parse a simple JSON string.

uses fpjson, LkJSON, jsontools;

procedure TForm1.Button1Click(Sender : TObject);
var
    str : String;
    js1 : TJsonObject;
    js2 : TlkJSONobject;
    js3 : TJsonNode;
begin
    str := '{"name":"\u95e8\u88ab\u8111\u5b50\u6324\u574f\u4e86"}';
    js1 := GetJson(str) as TJsonObject;
    js2 := TlkJSON.ParseText(str) as TlkJSONobject;
    js3 := TJsonNode.Create;
    js3.Parse(str);
    ShowMessage(
        js1.Get('name', '') + #13#10#13#10 +
        js2.getString('name') + #13#10#13#10 +
        js3.Find('name').AsString
    );
    js3.Free;
    js2.Free;
    js1.Free;
end;

The snapshot below shows the result. The fpjson gets a bad chinese string and the other two work fine.

P.S.

The LkJSON unit also has some bugs. Here is the version I modified, since the original version has not been updated for more than 10 years.

A bug when parsing \"\" was also found in the JsonTools unit. And it was fixed by @damoasda. I applied the fixed version of JsonTools here.

About

A demo project for Lazarus to show the parser bug of "fpjson" unit of Free Pascal.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages