Menu

#207 GExperts Macro Template Problem with "]" Character in Delphi 10.4

Closed
closed-fixed
5
2020-12-08
2020-08-05
Bruce
No

Using Delphi 10.4, if I create a template that ends with a closing square bracket, GExperts blanks out the template every time and won't accept the information. Adding a space after the ] will work though.

e.g. Cell[|] will be blanked.

Discussion

  • Thomas Mueller

    Thomas Mueller - 2020-09-29
    • assigned_to: Thomas Mueller
     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29

    The problem seems to be that the text is stored as CDATA in the XML file:

    which in itself already contains lots of square brackets, so at the end there is a triple bracket in this case which seems to break the parser.

     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29
     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29

    It does indeed break the parser:

    procedure TXMLCDATASection.ReadFromStream(const Parent: TXMLNode; const InputStream: IUnicodeStream);
    type
      TParserState = (psData, psInEnd, psEnd);
    var
      ReadChar: WideChar;
      PState: TParserState;
    begin
      PState := psData;
      // read next available character
      while InputStream.ProcessChar(ReadChar) do begin
        case PState of
          psData:
            if ReadChar = ']' then
              PState := psInEnd
            else
              InputStream.WriteOutputChar(ReadChar);
          psInEnd:
            if ReadChar = ']' then
              PState := psEnd
            else begin
              InputStream.WriteOutputChar(']');  // 2004-04-07 (mr): fixed bug
              InputStream.WriteOutputChar(ReadChar);
              PState := psData;
            end;
          psEnd:
            if ReadChar = '>' then begin
              NodeValue := InputStream.GetOutputBuffer;
              Exit;
            end
            else begin
              InputStream.WriteOutputChar(ReadChar);
              PState := psData;
            end;
        end;
      end;
    end;
    

    The triple ] will change the internal state from psEnd back to psData which is wrong because then it will not find the end of the CDATA entry until it hits the end of the file or the next CDATA entry.

     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29

    Oh great, the bug is fixed in the official repository, but not correctly. It works for 'Cell[|]' but not for other combinations, e.g.
    'Cell[|]]a'
    encoded as
    '<![CDATA[Cell[|]]a]]>'
    is read back as
    'Cell[|a'

     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29
    • status: open --> closed-fixed
    • Group: New --> Closed
     
  • Thomas Mueller

    Thomas Mueller - 2020-09-29

    fixed in revision #3327

     
  • Bruce

    Bruce - 2020-09-29

    Thanks. Just noticed today that "%s" may be an issue too...

     
    • Thomas Mueller

      Thomas Mueller - 2020-09-30

      Could you please be more specific? %s should not be a problem at all (at least not with XML parsing).

       
  • Bruce

    Bruce - 2020-09-30

    Just installed the newest version from SourceForge, and this template:

    Format('',[%s]);

    expands to:

    Format('',[Error!

     
    • Thomas Mueller

      Thomas Mueller - 2020-10-02

      This is not a bug but an invalid template: % is the character to enclose parameter strings like %BEGINPARAMLIST%, %PARAMNAME% etc. To add a literal % you need to duplicate it:

      Format('',[%%s]);

      I'll open a new bug report that there should be some kind of warning when defining such a template.

       
  • Bruce

    Bruce - 2020-12-08

    Thanks for fixing this!

     

Log in to post a comment.

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.
Try Free →