Skip to content

Commit 45fea56

Browse files
author
Sergio Andres Virviescas Santana
committed
Not add the last slash in optional paths
1 parent 252e686 commit 45fea56

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

path.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ func getOptionalPaths(path string) []string {
158158
newParam = true
159159
} else if i > 0 && newParam && c == '?' {
160160
p := strings.Replace(path[:index], "?", "", -1)
161+
p = p[:len(p)-1]
161162
if !gotils.StringSliceInclude(paths, p) {
162163
paths = append(paths, p)
163164
}
164165

165-
p = strings.Replace(path[:i], "?", "", -1) + "/"
166+
p = strings.Replace(path[:i], "?", "", -1)
166167
if !gotils.StringSliceInclude(paths, p) {
167168
paths = append(paths, p)
168169
}

path_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ func TestGetOptionalPath(t *testing.T) {
9999
}
100100

101101
expectedPaths := []string{
102-
"/show/:name/",
103-
"/show/:name/:surname/",
104-
"/show/:name/:surname/at/",
105-
"/show/:name/:surname/at/:address/",
106-
"/show/:name/:surname/at/:address/:id/",
107-
"/show/:name/:surname/at/:address/:id/:phone/",
102+
"/show/:name",
103+
"/show/:name/:surname",
104+
"/show/:name/:surname/at",
105+
"/show/:name/:surname/at/:address",
106+
"/show/:name/:surname/at/:address/:id",
107+
"/show/:name/:surname/at/:address/:id/:phone",
108108
}
109109
r := New()
110110
r.GET("/show/:name/:surname?/at/:address?/:id/:phone?", handler)

0 commit comments

Comments
 (0)