NucuCar.Domain: Fix multiple = bug in ConnectionStringParser

This commit is contained in:
Denis-Cosmin Nutiu 2020-02-01 17:36:17 +02:00
parent 2f6a97cf86
commit 1130464544
2 changed files with 12 additions and 2 deletions

View file

@ -25,8 +25,8 @@ namespace NucuCar.Domain.Utilities
var parsedConnectionString = new Dictionary<string, string>(); var parsedConnectionString = new Dictionary<string, string>();
foreach (var item in items) foreach (var item in items)
{ {
var keyValue = item.Split("="); var keyValue = item.Split("=", 2);
if (keyValue.Length != 2) if (keyValue.Length < 2)
{ {
throw new ArgumentException( throw new ArgumentException(
$"Invalid argument for connection string, expected KEY=VALUE got {item}"); $"Invalid argument for connection string, expected KEY=VALUE got {item}");

View file

@ -46,6 +46,16 @@ namespace NucuCar.UnitTests.NucuCar.Domain.Tests.Utilities
}); });
} }
[Fact]
private void Test_ConnectionStringParser_ValueWithMultipleEquals()
{
const string connectionString = "Test=1;Test2=base64=";
var parsedString = ConnectionStringParser.Parse(connectionString);
Assert.Equal("1", parsedString.GetValueOrDefault("Test"));
Assert.Equal("base64=", parsedString.GetValueOrDefault("Test2"));
}
} }
} }