Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

C#: Improve cs/invalid-string-formatting and add to the Code Quality suite. #19148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C#: Add more invalid-string-formatting testcases.
  • Loading branch information
michaelnebel committed Apr 24, 2025
commit 11dffc6647736598bd0957d9dcbf82d1214d9091
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;

class FormatInvalid
Expand Down Expand Up @@ -134,5 +135,27 @@ void FormatMethodTests()
ts.TraceInformation("{0}"); // GOOD
}

void CompositeFormatMethods()
{
var format = CompositeFormat.Parse("}"); // $ Alert

// GOOD: Format is invalid and this flagged during parsing.
String.Format<string>(null, format, "");
String.Format<string, string>(null, format, "", "");
String.Format<string, string, string>(null, format, "", "", "");

sb.AppendFormat(null, format, "");
sb.AppendFormat<string>(null, format, "");
sb.AppendFormat<string, string>(null, format, "", "");
sb.AppendFormat<string, string, string>(null, format, "", "", "");


var span = new Span<char>();
span.TryWrite(null, format, out _);
span.TryWrite<object>(null, format, out _, new object());
span.TryWrite<object, object>(null, format, out _, new object(), new object());
span.TryWrite<object, object, object>(null, format, out _, "", "", "");
}

System.IO.StringWriter sw;
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.