fcl-json: fixed StringToJSONString

This commit is contained in:
mattias 2022-05-21 03:27:27 +02:00
parent e03b920520
commit 5700cb56ac
3 changed files with 36 additions and 1 deletions

View File

@ -804,7 +804,7 @@ implementation
Uses typinfo;
const
HexDigits = '01234567890ABCDEF';
HexDigits: array[0..15] of char = '0123456789ABCDEF';
Resourcestring
SErrCannotConvertFromNull = 'Cannot convert data from Null value';

View File

@ -310,6 +310,9 @@ begin
C.SetValue('a','abc');
C.GetValue('a',L,'');
AssertStrings('String',L,['abc']);
C.SetValue('a','a'#1#2);
C.GetValue('a',L,'');
AssertStrings('String',L,['a'#1#2]);
C.SetValue('a',Integer(1));
C.GetValue('a',L,'');
AssertStrings('integer',L,['1']);

View File

@ -177,6 +177,7 @@ type
procedure TestCreateBoolean;
procedure TestCreateObject;
procedure TestCreateJSONString;
procedure TestCreateJSONStringSpecialChars;
procedure TestCreateJSONObject;
procedure TestCreateNilPointer;
procedure TestCreatePointer;
@ -2394,6 +2395,37 @@ begin
end;
end;
procedure TTestArray.TestCreateJSONStringSpecialChars;
const
S: array[0..7] of string = (
'A'#1,
'B'#9,
'C'#10,
'D'#12,
'E'#13,
'F'#10#13,
'G"Foo"',
'H\J');
Var
J : TJSONArray;
i: Integer;
begin
J:=TJSonArray.Create;
try
for i:=0 to high(S) do
J.Add(S[i]);
TestItemCount(J,length(S));
for i:=0 to high(S) do
begin
TestJSONType(J[i],jtString);
end;
TestJSON(J,'["A\u0001", "B\t", "C\n", "D\f", "E\r", "F\n\r", "G\"Foo\"", "H\\J"]');
finally
FreeAndNil(J);
end;
end;
procedure TTestArray.TestCreateObject;
Var