View Issue Details

IDProjectCategoryView StatusLast Update
0037352FPCFCLpublic2020-07-16 14:30
ReporterDomingo Galmés Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindows 64 bits 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0037352: Exceptions parsing json string with comments and empty lines with TJSONParser in package fpJson.
DescriptionExceptions parsing json string with comments and empty lines.
if i quit the comment or the empty line works well.
Steps To Reproduceprogram testJson1;

uses
  sysutils,classes,
  fpjson,jsonparser,jsonscanner;

procedure TestJson(AJson:string; ATitle:string);
var
  P : TJSONParser;
  J : TJSONData;
begin
  writeln('START TEST: '+ATitle);
  J:=nil;
  P:=TJSONParser.Create(AJson,[joComments]);
  Try
    try
      J:=P.Parse;
      writeln('TEST OK');
    except
      On E:Exception do writeln('EXCEPTION: '+E.Message);
    end;
    writeln('END TEST');
  finally
    FreeAndNil(J);
    FreeAndNil(P);
  end;
end;

const
  ENDLINE=#$0d#$0a;

var
  testString:string;

begin

  testString:=ENDLINE+
    '{'+ENDLINE+
      '"version":100,'+ENDLINE+
      '//comment'+ENDLINE+
      '"value":200'+ENDLINE+
    '}'+ENDLINE;
  TestJson(testString,'Test 1 Error at line 2 pos 1:expected element name got token "{" ');

  testString:='{'+ENDLINE+
      ''+ENDLINE+
      '"version":100, //comment'+ENDLINE+
      '"value":200'+ENDLINE+
    '}'+ENDLINE;
  TestJson(testString,'Test 1 ERROR Duplicate object member: "version"');

  testString:=ENDLINE+
    '{'+ENDLINE+
      '"version":100, //comment'+ENDLINE+
      '"value":200'+ENDLINE+
    '}'+ENDLINE;
  TestJson(testString,'Test 1 ERROR with initial empty line');

  testString:=ENDLINE+
    '{'+ENDLINE+
      '"version":100,'+ENDLINE+
      '"value":200'+ENDLINE+
    '}'+ENDLINE;
  TestJson(testString,'Test 1 OK without comment');

  testString:='{'+ENDLINE+
    '"version":100, //comment'+ENDLINE+
    '"value":200'+ENDLINE+
  '}'+ENDLINE;
  TestJson(testString,'Test 1 OK without initial empty line');

  writeln('Press Enter to end');
  readln;
end.
TagsNo tags attached.
Fixed in Revision45789
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

Michael Van Canneyt

2020-07-15 11:24

administrator   ~0124032

Fixed, thanks for reporting !

Domingo Galmés

2020-07-15 16:05

reporter   ~0124044

Sorry, but the next json text also gives wrong result.
Error at line 1 pos 13 Expected element name got token "{"

  testString:='//comment1'+ENDLINE+
      '{'+ENDLINE+
      '"version":100, //comment2'+ENDLINE+
      '"value":200'+ENDLINE+
    '}'+ENDLINE;

Michael Van Canneyt

2020-07-15 16:34

administrator   ~0124048

fixed new case in 45792.

If you find more cases, please report them in separate bugs, thank you !

Domingo Galmés

2020-07-16 14:30

reporter   ~0124093

Thanks for your fast resolution!

Issue History

Date Modified Username Field Change
2020-07-14 22:01 Domingo Galmés New Issue
2020-07-14 22:47 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-07-14 22:47 Michael Van Canneyt Status new => assigned
2020-07-15 11:24 Michael Van Canneyt Status assigned => resolved
2020-07-15 11:24 Michael Van Canneyt Resolution open => fixed
2020-07-15 11:24 Michael Van Canneyt Fixed in Version => 3.3.1
2020-07-15 11:24 Michael Van Canneyt Fixed in Revision => 45789
2020-07-15 11:24 Michael Van Canneyt FPCTarget => 4.0.0
2020-07-15 11:24 Michael Van Canneyt Note Added: 0124032
2020-07-15 16:05 Domingo Galmés Status resolved => feedback
2020-07-15 16:05 Domingo Galmés Resolution fixed => open
2020-07-15 16:05 Domingo Galmés Note Added: 0124044
2020-07-15 16:34 Michael Van Canneyt Status feedback => resolved
2020-07-15 16:34 Michael Van Canneyt Resolution open => fixed
2020-07-15 16:34 Michael Van Canneyt Note Added: 0124048
2020-07-16 14:30 Domingo Galmés Status resolved => closed
2020-07-16 14:30 Domingo Galmés Note Added: 0124093