Browse Source

* Better fix for bug ID #0037352

git-svn-id: trunk@45792 -
michael 5 years ago
parent
commit
6e9095be79
2 changed files with 34 additions and 3 deletions
  1. 4 3
      packages/fcl-json/src/jsonscanner.pp
  2. 30 0
      packages/fcl-json/tests/testjsonparser.pp

+ 4 - 3
packages/fcl-json/src/jsonscanner.pp

@@ -212,7 +212,8 @@ function TJSONScanner.FetchToken: TJSONToken;
       While Not (FCurPos^ in [#0,#10,#13]) do
         Inc(FCurPos);
       FEOL:=FCurPos;
-      While (FCurPos^<>#0) and (FCurPos^ in [#10,#13]) do
+      If (FCurPos^<>#0) then
+//      While (FCurPos^<>#0) and (FCurPos^ in [#10,#13]) do
         begin
         if (FCurPos^=#13) and (FCurPos[1]=#10) then
           Inc(FCurPos); // Skip CR-LF
@@ -471,7 +472,7 @@ begin
               TokenStart:=FTokenStr;
               SectionLength := PChar(FEOL)-TokenStart;
               SetString(FCurTokenString, TokenStart, SectionLength);
-              FTokenStr:=FCurPos;
+              FetchLine;
               end;
         '*' :
           begin
@@ -479,7 +480,7 @@ begin
           Inc(FTokenStr);
           TokenStart:=FTokenStr;
           Repeat
-            if (FTokenStr^=#0) then
+            if (FTokenStr=FEOL) then
               begin
               SectionLength := (FTokenStr - TokenStart);
               S:='';

+ 30 - 0
packages/fcl-json/tests/testjsonparser.pp

@@ -73,6 +73,7 @@ type
     Procedure TestStartEmptyLine;
     Procedure TestObjectEmptyLine;
     Procedure TestCommentLine;
+    Procedure TestFirstLineComment;
   end;
 
 implementation
@@ -651,6 +652,35 @@ begin
     end;
 end;
 
+procedure TTestParser.TestFirstLineComment;
+
+// New case
+const
+  ENDLINE = #$0d#$0a;
+
+
+Const
+  MyJSON =
+        '//comment1'+ENDLINE+
+              '{'+ENDLINE+
+              '"version":100, //comment2'+ENDLINE+
+              '"value":200'+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