Skip to content

Commit

Permalink
Patch potential string.Format exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ButterscotchV committed May 28, 2021
1 parent 9711bb3 commit 2c3fcf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MultiAdmin/Server.cs
Expand Up @@ -144,7 +144,7 @@ private set
// Update related variables
LogDirFile = string.IsNullOrEmpty(value) || string.IsNullOrEmpty(logDir)
? null
: $"{Path.Combine(logDir, value)}_{{0}}_log_{Port}.txt";
: $"{Path.Combine(logDir.EscapeFormat(), value)}_{{0}}_log_{Port}.txt";

lock (this)
{
Expand Down
10 changes: 10 additions & 0 deletions MultiAdmin/Utility/StringExtensions.cs
Expand Up @@ -39,5 +39,15 @@ public static bool Equals(this string input, string value, int startIndex)

return Equals(input, value, startIndex, length);
}

/// <summary>
/// Escapes this <see cref="string"/> for use with <see cref="string.Format"/>
/// </summary>
/// <param name="input">The <see cref="string"/> to escape</param>
/// <returns>A <see cref="string"/> escaped for use with <see cref="string.Format"/></returns>
public static string EscapeFormat(this string input)
{
return input?.Replace("{", "{{").Replace("}", "}}");
}
}
}

0 comments on commit 2c3fcf7

Please sign in to comment.