Skip to content

Treat a C# verbatim string as literal in the comment masker #462

Closed

Description

@ptr727

strip_strings() treats a backslash as an escape inside every quoted span. In a C# verbatim string (@"...") the backslash is literal, so a verbatim string ending in one consumes its own closing quote, the masker never leaves the string, and the rest of the line is blanked:

LINE : var p = @"C:\tmp\"; // Two things. Here.
MASK : var p = @"
EXTR : []

The trailing comment is invisible to extracted_comments(), so every comment rule goes blind on that line.

Scope

  • False negatives only. A comment goes unseen; no code line is reported as prose. That is the opposite direction from the defect fixed in Bound block-comment scanning by the earliest line-comment marker #461.
  • Line-scoped. strip_strings() resets its quote state per line, so a broken line cannot corrupt the lines below it.
  • Warn-only today. comment-wrap and comment-case report without gating, and charset plus dupword are what gate, so nothing fails CI because of this.
  • C# only. No other fleet syntax has a verbatim-string form.

The related half

The verbatim escape for a quote is a doubled "", not \". The masker reads the first as closing and the second as reopening, so @"say ""hi"" now" is mis-paired even without a trailing backslash.

Fix sketch

Recognize the @" opener and mask to the next unpaired ", treating "" as a literal quote and the backslash as an ordinary character. The syntax table would need to say that C-like covers a language with verbatim strings, since the masker is currently language-agnostic within C_LIKE and .js, .ts, .json, and .jsonc share that entry while having no verbatim form.

Wanting a case in test_prose_lint.py covering @"C:\tmp\" with a trailing comment, watched failing first.

Found by Copilot in the low-confidence block of its review of promotion PR #460, and deferred there rather than expanding that promotion.

Activity

  1. added a commit that references this issue on Jul 31, 2026
    7bf8a12
  2. ptr727 commented on Jul 31, 2026

    @ptr727
    OwnerAuthor

    Fixed in #464, squashed to develop as 7bf8a12.

    Both halves are covered: a verbatim string ending in a backslash keeps its closing quote, and a doubled quote is read as one escaped character rather than a close and a reopen. C# took its own syntax entry for it, since .c, .cpp, .js, .ts, .json, and .jsonc share the C-like markers but have no verbatim form.

    Two further cases came out of the review of that PR and are fixed with it: the interpolated spellings @$" and $@" are both recognized, and verbatim rules are restricted to the double-quoted form so @'a''b' is read as an ordinary char literal.

    Closing by hand rather than by keyword, since the fix landed on develop and Closes only fires on a merge into the default branch. It reaches main with promotion #460.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions