go-restful icon indicating copy to clipboard operation
go-restful copied to clipboard

regex route path allows partial match

Open haitch opened this issue 9 months ago • 5 comments

to accept case-insensitive paths, we use {h:(?i)hello}, to accept /HELLO, /hello, /Hello.

but with this approach, it also triggered a bug where /xxxHello, /yyyHello also got accepted.

package main

import (
	"io"
	"log"
	"net/http"

	restful "github.com/emicklei/go-restful/v3"
)

func main() {
	ws := new(restful.WebService)
	ws.Route(ws.GET("/{h:(?i)hello}").To(hello))
	restful.Add(ws)

	log.Fatal(http.ListenAndServe(":8080", nil))
}

func hello(req *restful.Request, resp *restful.Response) {
	io.WriteString(resp, "world")
}

haitch avatar May 21 '24 00:05 haitch