-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFormatInvalid.qhelp
More file actions
49 lines (40 loc) · 1.32 KB
/
FormatInvalid.qhelp
File metadata and controls
49 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
The format string supplied to formatting methods (such as <code>string.Format()</code>)
must be formatted correctly, otherwise the exception <code>System.FormatException</code>
will be thrown.
</p>
</overview>
<recommendation>
<p>
Change the format string so that it is correctly formatted. Ensure that each
format item adheres to the syntax:
</p>
<blockquote>
<p><b>{</b><i>index</i>[<b>,</b><i>alignment</i>][<b>:</b><i>formatString</i>]<b>}</b></p>
</blockquote>
<p>
When literals <code>{</code> or <code>}</code> are required, replace them with <code>{{</code> and
<code>}}</code>, respectively, or supply them as arguments.
</p>
</recommendation>
<example>
<p>
In this example, a format string uses both literals <code>{</code> and <code>}</code>, but the
literals are not properly escaped.
</p>
<sample src="FormatInvalidBad.cs" />
<p>
In the revised example, the literals are properly escaped.
</p>
<sample src="FormatInvalidGood.cs" />
</example>
<references>
<li>MSDN: <a href="https://msdn.microsoft.com/en-us/library/system.string.format.aspx">String.Format Method</a>.</li>
<li>Microsoft: <a href="https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting">Composite Formatting</a>.</li>
</references>
</qhelp>