Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions