提交 7e1bb21a 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #16218 from CyrusNajmabadi/outliningCrash

Fix crash in outlining when indexing out of an incomplete multiline comment.
Fixes #16186
......@@ -144,5 +144,15 @@ public async Task TestUsingKeywordWithSpace()
await VerifyBlockSpansAsync(code,
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
[WorkItem(16186, "https://github.com/dotnet/roslyn/issues/16186")]
public async Task TestInvalidComment()
{
const string code = @"$${|span:/*/|}";
await VerifyBlockSpansAsync(code,
Region("span", "/* / ...", autoCollapse: true));
}
}
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ internal static class CSharpStructureHelpers
public const string Ellipsis = "...";
public const string MultiLineCommentSuffix = "*/";
public const int MaxXmlDocCommentBannerLength = 120;
private static readonly char[] s_newLineCharacters = new char[] { '\r', '\n' };
private static int GetCollapsibleStart(SyntaxToken firstToken)
{
......@@ -113,7 +114,7 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
}
else if (comment.IsMultiLineComment())
{
var lineBreakStart = comment.ToString().IndexOfAny(new char[] { '\r', '\n' });
var lineBreakStart = comment.ToString().IndexOfAny(s_newLineCharacters);
var text = comment.ToString();
if (lineBreakStart >= 0)
......@@ -122,7 +123,9 @@ private static string GetCommentBannerText(SyntaxTrivia comment)
}
else
{
text = text.EndsWith(MultiLineCommentSuffix) ? text.Substring(0, text.Length - MultiLineCommentSuffix.Length) : text;
text = text.Length >= "/**/".Length && text.EndsWith(MultiLineCommentSuffix)
? text.Substring(0, text.Length - MultiLineCommentSuffix.Length)
: text;
}
return CreateCommentBannerTextWithPrefix(text, "/*");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册