Skip to content

Commit 175e4ec

Browse files
committed
C#: Add more format testcases.
1 parent 327ddb0 commit 175e4ec

File tree

2 files changed

+119
-54
lines changed

2 files changed

+119
-54
lines changed

csharp/ql/test/query-tests/API Abuse/FormatInvalid/FormatInvalid.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ void FormatMethodTests()
7272
Format("}", 0);
7373

7474
// BAD: All of these are format methods with an invalid string.
75+
String.Format("}"); // $ Alert
7576
String.Format("}", 0); // $ Alert
7677
String.Format("}", ps); // $ Alert
7778
String.Format(fp, "}", ps); // $ Alert
7879
String.Format("}", 0, 1); // $ Alert
7980
String.Format("}", 0, 1, 2); // $ Alert
8081
String.Format("}", 0, 1, 2, 3); // $ Alert
8182

83+
sb.AppendFormat("}"); // $ Alert
8284
sb.AppendFormat("}", 0); // $ Alert
8385
sb.AppendFormat("}", ps); // $ Alert
8486
sb.AppendFormat(fp, "}", ps); // $ Alert
@@ -117,6 +119,19 @@ void FormatMethodTests()
117119
System.Diagnostics.Debug.Print("}", ps); // $ Alert
118120

119121
Console.WriteLine("}"); // GOOD
122+
123+
// The Following methods are not recognised as format methods.
124+
Console.WriteLine("{0}"); // GOOD
125+
Console.Write("{0}"); // GOOD
126+
tw.WriteLine("{0}"); // GOOD
127+
tw.Write("{0}"); // GOOD
128+
System.Diagnostics.Debug.Print("{0}"); // GOOD
129+
System.Diagnostics.Debug.WriteLine("{0}"); // GOOD
130+
System.Diagnostics.Debug.Write("{0}"); // GOOD
131+
System.Diagnostics.Trace.TraceError("{0}"); // GOOD
132+
System.Diagnostics.Trace.TraceInformation("{0}"); // GOOD
133+
System.Diagnostics.Trace.TraceWarning("{0}"); // GOOD
134+
ts.TraceInformation("{0}"); // GOOD
120135
}
121136

122137
System.IO.StringWriter sw;

0 commit comments

Comments
 (0)