mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 03:25:41 +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>
|
/// <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)
|
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 &&
|
if (value is null)
|
||||||
Regex.IsMatch(str, "\\s")
|
{
|
||||||
? $"\"{str}\""
|
return string.Empty;
|
||||||
: value.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var strings = dictionary.Select(o => $"{o.Key}={SanitizeValue(o.Value)}");
|
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?.ToString())}");
|
||||||
return string.Join(";", strings);
|
return string.Join(";", strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user