mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 21:11:23 +02:00
* Patches for bugs 16815 and 16807 (double type and access violation when accessing non-existent member
git-svn-id: trunk@15495 -
This commit is contained in:
parent
f72526b95f
commit
0a4e4d3c62
@ -27,7 +27,7 @@ uses
|
|||||||
type
|
type
|
||||||
|
|
||||||
TJSONtype = (jtUnknown, jtNumber, jtString, jtBoolean, jtNull, jtArray, jtObject);
|
TJSONtype = (jtUnknown, jtNumber, jtString, jtBoolean, jtNull, jtArray, jtObject);
|
||||||
TJSONFloat = Extended;
|
TJSONFloat = Double;
|
||||||
TJSONStringType = AnsiString;
|
TJSONStringType = AnsiString;
|
||||||
TJSONCharType = AnsiChar;
|
TJSONCharType = AnsiChar;
|
||||||
PJSONCharType = ^TJSONCharType;
|
PJSONCharType = ^TJSONCharType;
|
||||||
@ -422,7 +422,7 @@ Resourcestring
|
|||||||
SErrPointerNotNil = 'Cannot add non-nil pointer to JSON%s';
|
SErrPointerNotNil = 'Cannot add non-nil pointer to JSON%s';
|
||||||
SErrOddNumber = 'TJSONObject must be constructed with name,value pairs';
|
SErrOddNumber = 'TJSONObject must be constructed with name,value pairs';
|
||||||
SErrNameMustBeString = 'TJSONObject constructor element name at pos %d is not a string';
|
SErrNameMustBeString = 'TJSONObject constructor element name at pos %d is not a string';
|
||||||
|
SErrNonexistentElement = 'Unknown object member: "%s"';
|
||||||
|
|
||||||
Function StringToJSONString(S : TJSONStringType) : TJSONStringType;
|
Function StringToJSONString(S : TJSONStringType) : TJSONStringType;
|
||||||
|
|
||||||
@ -1473,6 +1473,8 @@ end;
|
|||||||
function TJSONObject.GetElements(AName: string): TJSONData;
|
function TJSONObject.GetElements(AName: string): TJSONData;
|
||||||
begin
|
begin
|
||||||
Result:=TJSONData(FHash.Find(AName));
|
Result:=TJSONData(FHash.Find(AName));
|
||||||
|
If (Result=Nil) then
|
||||||
|
Raise EJSON.CreateFmt(SErrNonexistentElement,[AName]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSONObject.GetFloats(AName : String): TJSONFloat;
|
function TJSONObject.GetFloats(AName : String): TJSONFloat;
|
||||||
|
@ -157,6 +157,7 @@ type
|
|||||||
TTestObject = class(TTestJSON)
|
TTestObject = class(TTestJSON)
|
||||||
private
|
private
|
||||||
procedure TestAddBoolean(B : Boolean);
|
procedure TestAddBoolean(B : Boolean);
|
||||||
|
Procedure TestAccessError;
|
||||||
published
|
published
|
||||||
Procedure TestCreate;
|
Procedure TestCreate;
|
||||||
Procedure TestCreateString;
|
Procedure TestCreateString;
|
||||||
@ -184,6 +185,7 @@ type
|
|||||||
procedure TestRemove;
|
procedure TestRemove;
|
||||||
procedure TestClone;
|
procedure TestClone;
|
||||||
procedure TestExtract;
|
procedure TestExtract;
|
||||||
|
Procedure TestNonExistingAccessError;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -998,7 +1000,7 @@ end;
|
|||||||
procedure TTestArray.TestCreateFloat;
|
procedure TTestArray.TestCreateFloat;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
S = 1.2;
|
S : double = 1.2;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
J : TJSONArray;
|
J : TJSONArray;
|
||||||
@ -1564,6 +1566,20 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestObject.TestAccessError;
|
||||||
|
|
||||||
|
Var
|
||||||
|
J : TJSONObject;
|
||||||
|
|
||||||
|
begin
|
||||||
|
J:=TJSonObject.Create;
|
||||||
|
try
|
||||||
|
J.Strings['NonExist'];
|
||||||
|
finally
|
||||||
|
FreeAndNil(J);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestObject.TestAddBooleanTrue;
|
procedure TTestObject.TestAddBooleanTrue;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -1812,6 +1828,11 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestObject.TestNonExistingAccessError;
|
||||||
|
begin
|
||||||
|
AssertException(EJSON,@TestAccessError);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TTestObject.TestCreateString;
|
procedure TTestObject.TestCreateString;
|
||||||
|
|
||||||
@ -1907,7 +1928,7 @@ procedure TTestObject.TestCreateFloat;
|
|||||||
|
|
||||||
Const
|
Const
|
||||||
A = 'A';
|
A = 'A';
|
||||||
S = 1.2;
|
S : double = 1.2;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
J : TJSONObject;
|
J : TJSONObject;
|
||||||
|
@ -209,9 +209,9 @@ begin
|
|||||||
DoTestArray('[1234567890123456]',1);
|
DoTestArray('[1234567890123456]',1);
|
||||||
DoTestArray('[1234567890123456, 2234567890123456]',2);
|
DoTestArray('[1234567890123456, 2234567890123456]',2);
|
||||||
DoTestArray('[1234567890123456, 2234567890123456, 3234567890123456]',3);
|
DoTestArray('[1234567890123456, 2234567890123456, 3234567890123456]',3);
|
||||||
Str(1.2,S1);
|
Str(Double(1.2),S1);
|
||||||
Str(2.3,S2);
|
Str(Double(2.3),S2);
|
||||||
Str(3.4,S3);
|
Str(Double(3.4),S3);
|
||||||
DoTestArray('['+S1+']',1);
|
DoTestArray('['+S1+']',1);
|
||||||
DoTestArray('['+S1+', '+S2+']',2);
|
DoTestArray('['+S1+', '+S2+']',2);
|
||||||
DoTestArray('['+S1+', '+S2+', '+S3+']',3);
|
DoTestArray('['+S1+', '+S2+', '+S3+']',3);
|
||||||
|
Loading…
Reference in New Issue
Block a user