Skip to content

Commit

Permalink
Tolerate trailing semicolon in RabbitMQ connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-toporet committed May 13, 2024
1 parent 8b55274 commit 78d3bcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ public void virtual_host()
ConnectionStringParser.Apply("virtualhost=weird", theFactory);
theFactory.VirtualHost.ShouldBe("weird");
}

[Theory]
[InlineData("host=foo;port=5673;")]
[InlineData("host=foo;port=5673")]
public void trailing_semicolon_is_optional(string connectionString)
{
ConnectionStringParser.Apply(connectionString, theFactory);
theFactory.HostName.ShouldBe("foo");
theFactory.Port.ShouldBe(5673);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class ConnectionStringParser
{
public static void Apply(string connectionString, ConnectionFactory factory)
{
var values = connectionString.ToDelimitedArray(';');
var values = connectionString.ToDelimitedArray(';').Where(x => x.IsNotEmpty());
foreach (var value in values)
{
var parts = value.ToDelimitedArray('=');
Expand All @@ -28,7 +28,7 @@ internal static void Parse(string key, string value, ConnectionFactory factory)
case "host":
factory.HostName = value;
break;

case "port":
if (int.TryParse(value, out var port))
{
Expand All @@ -41,23 +41,23 @@ internal static void Parse(string key, string value, ConnectionFactory factory)
}

break;

case "username":
factory.UserName = value;
break;

case "password":
factory.Password = value;
break;

case "usetls":
Console.WriteLine("Wolverine does not respect the UseTLS flag, you will need to configure that directly on ConnectionFactory");
break;

case "virtualhost":
factory.VirtualHost = value;
break;

case "requestedheartbeat":
if (int.TryParse(value, out var heartbeat))
{
Expand All @@ -70,7 +70,7 @@ internal static void Parse(string key, string value, ConnectionFactory factory)
}

break;

default:
throw new ArgumentOutOfRangeException(nameof(key), $"Unknown connection string property '{key}'.");
}
Expand Down

0 comments on commit 78d3bcf

Please sign in to comment.