Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVED] Trim trailing slash if set on server address which can cause errors during lookup #1654

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ func processUrlString(url string) []string {
urls := strings.Split(url, ",")
var j int
for _, s := range urls {
u := strings.TrimSpace(s)
u := strings.TrimSuffix(strings.TrimSpace(s), "/")
if len(u) > 0 {
urls[j] = u
j++
Expand Down
4 changes: 4 additions & 0 deletions nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestSimplifiedURLs(t *testing.T) {
{
"nats",
[]string{
"nats://host1:1234/",
"nats://host1:1234",
"nats://host2:",
"nats://host3",
Expand All @@ -242,6 +243,7 @@ func TestSimplifiedURLs(t *testing.T) {
"[17:18:19:20]:1234",
},
[]string{
"nats://host1:1234/",
"nats://host1:1234",
"nats://host2:4222",
"nats://host3:4222",
Expand Down Expand Up @@ -434,6 +436,7 @@ func TestUrlArgument(t *testing.T) {
check("nats://localhost:1222 ", oneExpected)
check(" nats://localhost:1222", oneExpected)
check(" nats://localhost:1222 ", oneExpected)
check("nats://localhost:1222/", oneExpected)

var multiExpected = []string{
"nats://localhost:1222",
Expand All @@ -445,6 +448,7 @@ func TestUrlArgument(t *testing.T) {
check("nats://localhost:1222, nats://localhost:1223, nats://localhost:1224", multiExpected)
check(" nats://localhost:1222, nats://localhost:1223, nats://localhost:1224 ", multiExpected)
check("nats://localhost:1222, nats://localhost:1223 ,nats://localhost:1224", multiExpected)
check("nats://localhost:1222/,nats://localhost:1223/,nats://localhost:1224/", multiExpected)
}

func TestParserPing(t *testing.T) {
Expand Down