Преглед изворни кода

* Raise exception in case of no JSON and joSingle. Fix issue #41588

Michaël Van Canneyt пре 3 дана
родитељ
комит
ddf7126972
1 измењених фајлова са 8 додато и 3 уклоњено
  1. 8 3
      packages/fcl-json/src/jsonparser.pp

+ 8 - 3
packages/fcl-json/src/jsonparser.pp

@@ -66,6 +66,8 @@ implementation
 
 Resourcestring
   SErrStructure = 'Structural error';
+  SErrUnexpectedEOF = 'Unexpected EOF encountered.';
+  SErrDuplicateKey = 'Duplicatekey or no object';
 
 { TJSONParser }
 
@@ -78,9 +80,10 @@ Var
 
 begin
   Data:=Nil;
-  AOptions:=[];
+  AOptions:=[joSingle];
   if AUseUTF8 then
     Include(AOptions,joUTF8);
+    
   P:=TJSONParser.Create(AStream,AOptions);
   try
     Data:=P.Parse;
@@ -98,7 +101,7 @@ Var
 
 begin
   Data:=Nil;
-  AOptions:=[];
+  AOptions:=[joSingle];
   if AUseUTF8 then
     Include(AOptions,joUTF8);
   P:=TJSONParser.Create(S,AOptions);
@@ -164,7 +167,7 @@ begin
   if (FStruct<>nil) and (FStruct.JSONType=jtObject) and (FKey='') then
     FKey:=Akey
   else
-    DoError('Duplicatekey or no object');
+    DoError(SErrDuplicateKey);
 end;
 
 procedure TJSONParser.StringValue(const AValue: TJSONStringType);
@@ -240,6 +243,8 @@ begin
   try
     DoExecute;
     Result:=FValue;
+    if (Result=Nil) and (joSingle in Options) then
+      Raise EJSONParser.Create(SErrUnexpectedEOF); 
   except
     On E : exception do
       begin