#1 2016-04-30 15:01:31

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

Maybe a bug or not

HI,

Look at this array:

[{"Name":"Paul","born":isodate("1969-12-31")}]

I discovered that function below can not read it, so I made a small change.




function GotoNextJSONObjectOrArrayInternal(P,PMax: PUTF8Char; EndChar: AnsiChar): PUTF8Char;
label Prop;
begin
  result := nil;
  repeat
    case P^ of
    '{','[': begin
      if PMax=nil then
        P := GotoNextJSONObjectOrArray(P) else
        P := GotoNextJSONObjectOrArrayMax(P,PMax);
      if P=nil then exit;
    end;
    ':': if EndChar<>'}' then exit else inc(P); // syntax for JSON object only
    ',': inc(P); // comma appears in both JSON objects and arrays
    '}': if EndChar='}' then break else exit;
    ']': if EndChar=']' then break else exit;
    '"': begin
      P := GotoEndOfJSONString(P);
      if P^<>'"' then
        exit;
      inc(P);
    end;
    '-','+','0'..'9': // '0123' excluded by JSON, but not here
      repeat
        inc(P);
      until not (P^ in DigitFloatChars);
    't': if PInteger(P)^=TRUE_LOW then inc(P,4) else goto Prop;
    'f': if PInteger(P)^=FALSE_LOW then inc(P,5) else goto Prop;
    'n': if PInteger(P)^=NULL_LOW then inc(P,4) else goto Prop;
    '''': begin
      repeat inc(P); if P^<=' ' then exit; until P^='''';
      repeat inc(P) until not(P^ in [#1..' ']);
      if P^<>':' then exit;
    end;
    '/': begin
      repeat // allow extended /regex/ syntax
        inc(P);
        if P^=#0 then
          exit;
      until P^='/';
      repeat inc(P) until not(P^ in [#1..' ']);
    end;
    else
    begin
Prop: if not (P^ in ['_','A'..'Z','a'..'z','0'..'9','$']) then
        exit; // expect e.g. '{age:{$gt:18}}'
      repeat
        inc(P);
       until not (P^ in ['_','A'..'Z','a'..'z','0'..'9','.']);
       while P^ in [#1..' '] do inc(P);
/////////////////////////////////////////////////////////////////////// start
       if P^ ='(' then
       begin
        inc(p);
        while P^ in [#1..' '] do inc(P);
        if p^='"' then
        begin
         P := GotoEndOfJSONString(P);
         if P^<>'"' then
          exit;
        end;
        inc(p);
        while P^ in [#1..' '] do inc(P);
        if P^<>')' then
          exit;
        inc(p);
       end
       else 
/////////////////////////////////////////////////////////////////////// end
        if P^<>':' then
        exit;
    end;
    end;
    if P^ in [#1..' '] then repeat inc(P) until not(P^ in [#1..' ']);
    if (PMax<>nil) and (P>=PMax) then
      exit;
  until P^=EndChar;
  result := P+1;
end;

Offline

#2 2016-05-01 12:08:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: Maybe a bug or not

Included as http://synopse.info/fossil/info/4d5d975555

Thanks for the feedback!

Offline

Board footer

Powered by FluxBB