TurboPack / SynEdit

SynEdit is a syntax highlighting edit control, not based on the Windows common controls.
216 stars 72 forks source link

SynHighlighterJSON fails on Number value=0 #227

Closed CodehunterWorks closed 1 year ago

CodehunterWorks commented 1 year ago

Hello!

There is an Bug in SynHighlighterJSON.pas NumberProc:

 // ensure that a zero is followed by a dot
  if FLine[Run] = '0' then
    if FLine[Run + 1] <> '.' then
    begin
      FTokenID := tkUnknown;
      while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run);
      Exit;
    end;

This leads to wrong color for the Attribute in the next line, when the Value is 0, like that:

grafik

The red marked values are shown in AttributeAttri colors instead of NumberAttri colors and the next line Attribute is shown in ValueAttri colors instead of AttributeAttri colors. I think the current code is intended to draw decimal numbers below 1 correctly (0.1234) but ignores the possibility that an number value can simply 0.

Patch the code like that will fix the Problem:

  // ensure that a zero is followed by a dot
  if FLine[Run] = '0' then
    if FLine[Run + 1] <> '.' then
    begin
      if FLine[Run + 1] = ',' then
      begin
        Inc(Run);
        Exit;
      end;
      FTokenID := tkUnknown;
      while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run);
      Exit;
    end;

grafik