net/url JoinPath (Go 1.19) - elem を base と結合し ./ や ../ が取り除かれた URL 文字列を返す - 内部では url.Parse したあとに URL.JoinPath (Go 1.19) を呼んでいる // JoinPath returns a URL string with the provided path elements joined to // the existing path of base and the resulting path cleaned of any ./ or ../ elements. func JoinPath(base string, elem ...string) (result string, err error) { url, err := Parse(base) if err != nil { return } result = url.JoinPath(elem...).String() return }
参考 - https://twitter.com/golang/status/1567189780873486337?s=20&t=1NSLbARJbP_DS CsVPjJDPw - Go 1.19.1 and Go 1.18.6 are released - net/url: JoinPath doesn’t strip relative path components in all circumstances - https://go-review.googlesource.com/c/go/+/423514/ - https://github.com/golang/go/commit/28335508913a46e05ef0c 04a18e8a1a6beb775ec - https://pkg.go.dev/net/url#JoinPath - https://github.com/golang/go/blob/master/src/path/path_test.go