Skip to content

Commit 2c3fcf7

Browse files
committed
Patch potential string.Format exception
1 parent 9711bb3 commit 2c3fcf7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

MultiAdmin/Server.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private set
144144
// Update related variables
145145
LogDirFile = string.IsNullOrEmpty(value) || string.IsNullOrEmpty(logDir)
146146
? null
147-
: $"{Path.Combine(logDir, value)}_{{0}}_log_{Port}.txt";
147+
: $"{Path.Combine(logDir.EscapeFormat(), value)}_{{0}}_log_{Port}.txt";
148148

149149
lock (this)
150150
{

MultiAdmin/Utility/StringExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,15 @@ public static bool Equals(this string input, string value, int startIndex)
3939

4040
return Equals(input, value, startIndex, length);
4141
}
42+
43+
/// <summary>
44+
/// Escapes this <see cref="string"/> for use with <see cref="string.Format"/>
45+
/// </summary>
46+
/// <param name="input">The <see cref="string"/> to escape</param>
47+
/// <returns>A <see cref="string"/> escaped for use with <see cref="string.Format"/></returns>
48+
public static string EscapeFormat(this string input)
49+
{
50+
return input?.Replace("{", "{{").Replace("}", "}}");
51+
}
4252
}
4353
}

0 commit comments

Comments
 (0)