Browse Source

* Fix bug ID #37367

git-svn-id: trunk@45795 -
michael 5 years ago
parent
commit
0c8103b3a1
2 changed files with 43 additions and 7 deletions
  1. 8 7
      packages/fcl-json/src/jsonscanner.pp
  2. 35 0
      packages/fcl-json/tests/testjsonparser.pp

+ 8 - 7
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;

+ 35 - 0
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