Skip to content

Refuse a line break in a doc comment cref or name before writing [patch] - #160

Open
matt-edmondson wants to merge 1 commit into
mainfrom
claude/issue-159-multiline-doc-attribute
Open

matt-edmondson wants to merge 1 commit into
mainfrom
claude/issue-159-multiline-doc-attribute

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #159

What changed

DocComment.WriteTo checks every attribute value before it writes the first /// line. The values checked are InheritDocCref (when InheritDoc is set), each SeeAlso entry, and the Name of each TypeParams, Params and Exceptions entry. If any value contains a line terminator from LineTerminators (LF, CR, NEL, U+2028, U+2029), it throws ArgumentException and writes nothing. That is the same rule RegionScope applies to a multi-line region name.

Rejecting was the option the issue suggested. A cref or a parameter name that contains a line break is never valid, so encoding it as 
 would only move the error from the generated file to the compiler's cref resolution.

DocComment.WriteTo is the first thing TemplateBase.WriteTo writes. So a template whose documentation is rejected leaves no half-written declaration behind.

Tests

  • ALineBreakInAnAttributeValueIsRejectedBeforeWriting runs once per terminator (LF, CRLF, CR, NEL, U+2028, U+2029). For each one it covers SeeAlso, InheritDocCref, a param, a typeparam and an exception DocTag.Name, and asserts that the output stays empty.
  • AnUnusedInheritDocCrefIsNotChecked covers a cref that is set while InheritDoc is off. It is ignored, as the property documents, so it is not rejected.
  • With the fix reverted, the new test fails for every terminator ("no exception was thrown").
  • The full suite passes: 256 tests on net10.0.

Generated by Claude Code

A line terminator in InheritDocCref, a SeeAlso entry, or the Name of a
param, typeparam or exception DocTag ended the /// comment mid-attribute
and left the rest compiled as code. DocComment.WriteTo now checks every
attribute value first and throws ArgumentException, so nothing is written.

Fixes #159

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3C2EQ5hMiLw63t4Aa
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A line break in a DocComment cref or name (SeeAlso, InheritDocCref, param/typeparam/exception) moves the rest of it out of the /// comment

2 participants