Skip to content

Commit

Permalink
Merge branch 'mr/fix_integer_parsing' into 'master'
Browse files Browse the repository at this point in the history
Ensure large integers can be parsed in JSON data

See merge request eng/toolchain/gnatcoll-core!89
  • Loading branch information
Nikokrock committed Mar 22, 2024
2 parents e0c6cea + d1a2936 commit c83c7c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/gnatcoll-json.adb
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ package body GNATCOLL.JSON is
end;
when INTEGER_VALUE =>
Tmp := Create
(Integer'Value (Token (Buf, Event.First, Event.Last)));
(Long_Long_Integer'Value
(Token (Buf, Event.First, Event.Last)));
when NUMBER_VALUE =>
Tmp := Create
(Long_Float'Value (Token (Buf, Event.First, Event.Last)));
Expand Down
19 changes: 17 additions & 2 deletions testsuite/tests/json/integer_number/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ function Test return Integer is

use type JSON.JSON_Value_Type;

Content : constant String := "14";
begin
declare
Value : constant JSON.JSON_Value := JSON.Read
(Strm => Content,
(Strm => "14",
Filename => "<data>");
Result : Integer;
begin
Expand All @@ -23,5 +22,21 @@ begin
Result := JSON.Get (Value);
A.Assert (Result = 14, "check that result is equal to 14");
end;

declare
Value : constant JSON.JSON_Value := JSON.Read
(Strm => "9000000000000000000",
Filename => "<data>");
Result : Long_Long_Integer;
begin
A.Assert (True, "passed");
A.Assert (JSON.Kind (Value) = JSON.JSON_Int_Type,
"check if type is JSON_Int_Type (got " &
JSON.Kind (Value)'Img & ")");
Result := JSON.Get (Value);
A.Assert (Result = 9000000000000000000,
"check that result is equal to 9000000000000000000");
end;

return A.Report;
end Test;

0 comments on commit c83c7c4

Please sign in to comment.