* Fix bug ID #30606, identifier not allowed when parsing object

git-svn-id: trunk@34536 -
This commit is contained in:
michael 2016-09-17 08:18:53 +00:00
parent a80e8f41c4
commit 5be2dfd9c8
2 changed files with 18 additions and 7 deletions

View File

@ -148,6 +148,7 @@ begin
tkSQuaredBraceClose : DoError(SErrUnexpectedToken);
tkNumber : Result:=ParseNumber;
tkComma : DoError(SErrUnexpectedToken);
tkIdentifier : DoError(SErrUnexpectedToken);
end;
except
FreeAndNil(Result);

View File

@ -22,6 +22,9 @@ uses
Classes, SysUtils, fpcunit, testutils, testregistry,fpjson,
jsonscanner,jsonParser,testjsondata;
Const
DefaultOpts = [joUTF8,joStrict];
type
{ TTestParser }
@ -30,7 +33,7 @@ type
private
FOptions : TJSONOptions;
procedure CallNoHandlerStream;
procedure DoTestError(S: String);
procedure DoTestError(S: String; Options : TJSONOptions = DefaultOpts);
procedure DoTestFloat(F: TJSONFloat); overload;
procedure DoTestFloat(F: TJSONFloat; S: String); overload;
procedure DoTestObject(S: String; const ElNames: array of String; DoJSONTest : Boolean = True);
@ -53,6 +56,7 @@ type
procedure TestString;
procedure TestArray;
procedure TestObject;
procedure TestObjectError;
procedure TestTrailingComma;
procedure TestTrailingCommaErrorArray;
procedure TestTrailingCommaErrorObject;
@ -326,6 +330,12 @@ begin
DoTestObject('{ "a" : 1, "B" : { "c" : "d" } }',['a','B']);
end;
procedure TTestParser.TestObjectError;
begin
DoTestError('{ "name" : value }',[joUTF8]);
end;
procedure TTestParser.DoTestObject(S: String; const ElNames: array of String;
DoJSONTest: Boolean);
@ -406,21 +416,21 @@ end;
procedure TTestParser.TestErrors;
begin
{
DoTestError('a');
DoTestError('"b');
DoTestError('1Tru');
}
DoTestError('b"');
DoTestError('{"a" : }');
DoTestError('{"a" : ""');
DoTestError('{"a : ""');
{
DoTestError('[1,]');
DoTestError('[,]');
DoTestError('[,,]');
DoTestError('[1,,]');
}
end;
procedure TTestParser.TestClasses;
@ -516,7 +526,7 @@ begin
end;
end;
procedure TTestParser.DoTestError(S : String);
procedure TTestParser.DoTestError(S : String; Options : TJSONOptions = DefaultOpts);
Var
P : TJSONParser;
@ -527,7 +537,7 @@ Var
begin
ParseOK:=False;
P:=TJSONParser.Create(S);
P.Strict:=True;
P.OPtions:=Options;
J:=Nil;
Try
Try