diff --git a/packages/fcl-json/src/jsonscanner.pp b/packages/fcl-json/src/jsonscanner.pp index fc3f7429ae..3065194b1b 100644 --- a/packages/fcl-json/src/jsonscanner.pp +++ b/packages/fcl-json/src/jsonscanner.pp @@ -237,6 +237,7 @@ var OldLength, SectionLength, tstart,tcol, u1,u2: Integer; C , c2: char; S : String[4]; + Line : String; IsStar,EOC: Boolean; Procedure MaybeAppendUnicode; @@ -480,12 +481,12 @@ begin Inc(FTokenStr); TokenStart:=FTokenStr; Repeat - if (FTokenStr=FEOL) then + While (FTokenStr=FEOL) do begin SectionLength := (FTokenStr - TokenStart); - S:=''; - SetString(S, TokenStart, SectionLength); - FCurtokenString:=FCurtokenString+S; + Line:=''; + SetString(Line, TokenStart, SectionLength); + FCurtokenString:=FCurtokenString+Line+sLineBreak; if not fetchLine then Error(SUnterminatedComment, [CurRow,CurCOlumn,FTokenStr[0]]); TokenStart:=FTokenStr; @@ -497,9 +498,9 @@ begin if EOC then begin SectionLength := (FTokenStr - TokenStart-1); - S:=''; - SetString(S, TokenStart, SectionLength); - FCurtokenString:=FCurtokenString+S; + Line:=''; + SetString(Line, TokenStart, SectionLength); + FCurtokenString:=FCurtokenString+Line; Inc(FTokenStr); end; end; diff --git a/packages/fcl-json/tests/testjsonparser.pp b/packages/fcl-json/tests/testjsonparser.pp index 9178fab487..fd902be6fd 100644 --- a/packages/fcl-json/tests/testjsonparser.pp +++ b/packages/fcl-json/tests/testjsonparser.pp @@ -74,6 +74,7 @@ type Procedure TestObjectEmptyLine; Procedure TestCommentLine; Procedure TestFirstLineComment; + Procedure TestMultiLineComment; end; implementation @@ -681,6 +682,40 @@ begin end; +procedure TTestParser.TestMultiLineComment; + +// Issue 37367 + +const + ENDLINE = #$0d#$0a; + + +Const + MyJSON = + '/* long comment'+ENDLINE+ + ''+ENDLINE+ + ' error'+ENDLINE+ + '*/'+ENDLINE+ + '{'+ENDLINE+ + ' "version":100, //coment2 without comment2 works well '+ENDLINE+ + ' "valor":200 /*comment 3'+ENDLINE+ + ' line 2'+ENDLINE+ + ' */'+ENDLINE+ + '}'+ENDLINE; + +var + J : TJSONData; + +begin + With TJSONParser.Create(MyJSON,[joComments]) do + Try + J:=Parse; + J.Free; + Finally + Free; + end; +end; + procedure TTestParser.DoTestError(S : String; Options : TJSONOptions = DefaultOpts); Var