Menu ▾ ▴

#284 TCoolEdit: TSyntaxParser::ParseLine handles escape characters incorrectly

8
pending
1
2026-03-31
2014-11-16
No

The overrides for TSyntaxParser::ParseLine, e.g. in TCSyntaxParser for C++, handles escape characters in string and character literals incorrectly. The code only checks for two preceding escape characters ('\') to determine whether the current quote is escaped. It fails for strings that have more than two preceding escape characters. This bug leads to visual errors in source code highlighting in the CoolPrj editor class.

For example, for the string "\\\"..." (a backslash followed by a double-quote and some more text), the code assumes that the escaped double-quote is not escaped, because it is preceded by two escape characters, thus prematurely terminating the string literal.

The correct test is to check for an odd number of preceding escape characters to determine whether a character is escaped. The attached patch implements this fix. However, it only fixes the problem for TCSyntaxParser. Almost all of the syntax parsers have this flaw, so the code should be refactored to implement the fix in a reusable manner so that all parsers share common code. Currently, the parsers are implemented by cut-and-paste of the same code.

PS. Back-tracking is an awkward and inefficient way to find the end of a string literal. A better parsing solution should be used.

1 Attachments

Related

Discussion: CoolEdit and C++Builder

Discussion

  • Vidar Hasfjord

    Vidar Hasfjord - 2024-11-18
    • summary: CoolPrj's TSyntaxParser::ParseLine handles escape characters incorrectly --> TCoolEdit: TSyntaxParser::ParseLine handles escape characters incorrectly
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2024-11-18

    This issue needs reevaluation after the recent overhaul of the syntax highlighting parsers, as it is likely it no longer applies.

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2024-11-19
    • status: open --> closed
    • assigned_to: Vidar Hasfjord
    • Group: unspecified --> 8
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2024-11-19

    This issue has been resolved. See duplicate ticket [bugs:#582].

     

    Related

    Bugs: #582

  • Vidar Hasfjord

    Vidar Hasfjord - 2026-03-31
    • Status: closed --> pending
     

Log in to post a comment.