onryldz / x-superobject

Delphi Cross Platform Rapid JSON
316 stars 118 forks source link

Access Violation if closing bracket is missing on an object #111

Open Boberoo opened 7 years ago

Boberoo commented 7 years ago

Major problem.

If I create a SuperObject, and pass in JSON that has a missing closing bracket, I get a nasty access violation instead of a nice friendly error message.

For example, use JSON like this:

{ "name" : "Fred" , "surname" : "Jones"

Instead of:

{ "name" : "Fred" , "surname" : "Jones" }

The following fix seems to work nicely:

procedure TJSONBuilder.ReadObject(var Val: IJSONAncestor); var Name: String; begin LGen.KillLex; Val := TJSONObject.Create; repeat if LGen.CheckName(Name) then begin LGen.KillLex; if not LGen.CheckKill(ltColon) then raise TJSONSyntaxError.CreateFmt(Err_Expected, [':'], LGen.Current.Pos); TJSONObject(Val).AddPair(TJSONPair.Create(Name, ReadValue)); end until not LGen.CheckKill(ltVirgule);

if not LGen.CheckKill(ltBRight) then if LGen.Current = nil then //<<<<<<new raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.FCurrPos) //<<<<<<new else raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.Current.Pos); end;