File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,13 @@ func (c *Config) getServiceName() string {
21
21
if ! strings .HasPrefix (c .ServiceName , "/" ) {
22
22
return url .PathEscape (c .ServiceName )
23
23
}
24
+
24
25
// Otherwise new custom paths
25
- rawServiceName := c .ServiceName [1 :strings .LastIndex (c .ServiceName , "/" )] // trim from first to last '/'
26
+ lastIndex := strings .LastIndex (c .ServiceName , "/" )
27
+ if lastIndex < 1 {
28
+ lastIndex = 1
29
+ }
30
+ rawServiceName := c .ServiceName [1 :lastIndex ] // trim from first to last '/'
26
31
serviceNameParts := strings .Split (rawServiceName , "/" )
27
32
for i := range serviceNameParts {
28
33
serviceNameParts [i ] = url .PathEscape (serviceNameParts [i ])
Original file line number Diff line number Diff line change 1
1
package grpc
2
2
3
3
import (
4
- "github.com/stretchr/testify/assert"
5
4
"testing"
5
+
6
+ "github.com/stretchr/testify/assert"
6
7
)
7
8
8
9
func TestConfig_GetServiceName (t * testing.T ) {
@@ -31,6 +32,11 @@ func TestConfig_GetServiceName(t *testing.T) {
31
32
ServiceName : "/hello /world!/a|b" ,
32
33
Expected : "hello%20/world%21" ,
33
34
},
35
+ {
36
+ TestName : "path with only one '/'" ,
37
+ ServiceName : "/foo" ,
38
+ Expected : "" ,
39
+ },
34
40
}
35
41
for _ , test := range tests {
36
42
t .Run (test .TestName , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments