This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new 89724e001 fix urlString with muti addr trim space (#2979)
89724e001 is described below
commit 89724e001279d1b10f585d2290b710a5c1344e3e
Author: dongjiang <[email protected]>
AuthorDate: Thu Aug 21 14:13:49 2025 +0800
fix urlString with muti addr trim space (#2979)
Update common/url_test.go
Update common/url.go
Co-authored-by: Copilot <[email protected]>
---
common/url.go | 16 +++++++++++++++-
common/url_test.go | 18 ++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/common/url.go b/common/url.go
index 8da974da0..9e194ecb2 100644
--- a/common/url.go
+++ b/common/url.go
@@ -255,6 +255,20 @@ func NewURL(urlString string, opts ...Option) (*URL,
error) {
return &s, nil
}
+ // zookeeper, nacos, metadata address with multi addr trim space
+ urlStringTrim := func(s string) string {
+ parts := strings.Split(s, ",")
+ var nonEmptyParts []string
+ for _, part := range parts {
+ trimmed := strings.TrimSpace(part)
+ if trimmed != "" {
+ nonEmptyParts = append(nonEmptyParts, trimmed)
+ }
+ }
+ return strings.Join(nonEmptyParts, ",")
+ }
+ urlString = urlStringTrim(urlString)
+
rawURLString, err := url.QueryUnescape(urlString)
if err != nil {
return &s, perrors.Errorf("URL.QueryUnescape(%s), error{%v}",
urlString, err)
@@ -271,7 +285,7 @@ func NewURL(urlString string, opts ...Option) (*URL, error)
{
serviceURL, urlParseErr := url.Parse(rawURLString)
if urlParseErr != nil {
- return &s, perrors.Errorf("URL.Parse(URL string{%s}),
error{%v}", rawURLString, err)
+ return &s, perrors.Errorf("URL.Parse(URL string{%s}),
error{%v}", rawURLString, urlParseErr)
}
s.params, err = url.ParseQuery(serviceURL.RawQuery)
diff --git a/common/url_test.go b/common/url_test.go
index fcb437f9b..91880c266 100644
--- a/common/url_test.go
+++ b/common/url_test.go
@@ -574,3 +574,21 @@ func TestIsAnyCondition(t *testing.T) {
})
}
}
+
+func TestNewURLWithMultiAddr(t *testing.T) {
+ u1, err :=
NewURL("zookeeper://127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183")
+ assert.Nil(t, err)
+ assert.Equal(t, "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
u1.Location)
+
+ u2, err := NewURL("zookeeper://127.0.0.1:2181 , 127.0.0.1:2182,
127.0.0.1:2183")
+ assert.Nil(t, err)
+ assert.Equal(t, "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
u2.Location)
+
+ u3, err := NewURL("zookeeper://127.0.0.1:2181 , 127.0.0.1:2182,
127.0.0.1:2183,, , , ")
+ assert.Nil(t, err)
+ assert.Equal(t, "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
u3.Location)
+
+ u4, err := NewURL(" , ,127.0.0.1:2181 , 127.0.0.1:2182,
127.0.0.1:2183,, , , ", WithProtocol("zookeeper"))
+ assert.Nil(t, err)
+ assert.Equal(t, "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
u4.Location)
+}