Skip to content

Commit c8cbe20

Browse files
authored
Filter out empty path components (#1)
1 parent e2a0ba3 commit c8cbe20

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

cmd/happy/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,12 @@ func (t *tree) String() string {
609609

610610
func (t *tree) Write(w *codewriter.Writer, earlyExit string, visitor func(w *codewriter.Writer, endpoint endpoint)) {
611611
w.Import("strings")
612-
w.L(`parts := strings.Split(r.URL.Path, "/")`)
612+
w.L(`parts := []string{}`)
613+
w.L(`for i, p := range strings.Split(r.URL.Path, "/") {`)
614+
w.L(` if i == 0 || p != "" {`)
615+
w.L(` parts = append(parts, p)`)
616+
w.L(` }`)
617+
w.L(`}`)
613618
w.L(`var params []string`)
614619
w.L(`_ = params`)
615620
w.L(`switch parts[0] {`)

testdata/main_api.go

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)