Skip to content

Commit

Permalink
[IMPROVED] Trim trailing slash if set on server address which causes …
Browse files Browse the repository at this point in the history
…errors during look up (#1654)
  • Loading branch information
josephwoodward authored and piotrpio committed Jul 23, 2024
1 parent 1de5b00 commit 8c8fb4b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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

0 comments on commit 8c8fb4b

Please sign in to comment.