mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:48:46 +00:00
🐞 Fix for #20
Sanitize string input, rather than T. Call ToString() on dictionary value
This commit is contained in:
parent
6f26c04f6c
commit
3ad20fdb40
@ -19,15 +19,25 @@ namespace X10D
|
||||
/// <returns>Returns a <see cref="string" /> representing the dictionary as a key=value; set.</returns>
|
||||
public static string ToConnectionString<T1, T2>(this IReadOnlyDictionary<T1, T2> dictionary)
|
||||
{
|
||||
static string SanitizeValue<T>(T value)
|
||||
static string SanitizeValue(string? value)
|
||||
{
|
||||
return value is string str &&
|
||||
Regex.IsMatch(str, "\\s")
|
||||
? $"\"{str}\""
|
||||
: value.ToString();
|
||||
if (value is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
for (var index = 0; index < value.Length; index++)
|
||||
{
|
||||
if (char.IsWhiteSpace(value[index]))
|
||||
{
|
||||
return $"\"{value}\"";
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}");
|
||||
var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value?.ToString())}");
|
||||
return string.Join(";", strings);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user