Skip to content

Commit

Permalink
Escape special chars (RCS1181) (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 21, 2024
1 parent 48d201b commit df7ec0e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS0056](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0056) ([PR](https://github.com/dotnet/roslynator/pull/1521))
- Fix analyzer [RCS1181](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1181) ([PR](https://github.com/dotnet/roslynator/pull/1526))
- Fix analyzer [RCS0005](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0005) ([PR](https://github.com/dotnet/roslynator/pull/1533))
- Fix analyzer [RCS1181](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1181) ([PR](https://github.com/dotnet/roslynator/pull/1534))

## [4.12.5] - 2024-09-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,37 @@ void M()
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertCommentToDocumentationComment)]
public async Task Test_CommentContainsXmlSpecialChars()
{
await VerifyDiagnosticAndFixAsync("""
namespace N
{
/// <summary>
/// x
/// </summary>
class C
{
int P { get; set; } [|// Must be >= 0 & <= 5.|]
}
}
""", """
namespace N
{
/// <summary>
/// x
/// </summary>
class C
{
/// <summary>
/// Must be &gt;= 0 &amp; &lt;= 5.
/// </summary>
int P { get; set; }
}
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConvertCommentToDocumentationComment)]
public async Task TestNoDiagnostic_DocumentationComment()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,7 +62,10 @@ public static Task<Document> RefactorAsync(

Debug.Assert(trailingTrivia.Contains(trivia));

comments = ImmutableArray.Create(_leadingSlashesRegex.Replace(trivia.ToString(), ""));
string commentText = _leadingSlashesRegex.Replace(trivia.ToString(), "");
commentText = WebUtility.HtmlEncode(commentText);

comments = ImmutableArray.Create(commentText);

SyntaxToken newToken = token.WithTrailingTrivia(trailingTrivia.Skip(trailingTrivia.IndexOf(trivia) + 1));

Expand Down

0 comments on commit df7ec0e

Please sign in to comment.