mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-10 08:59:57 +00:00
hls, webrtc: fix appending slash to paths that contain slashes (#2773)
This commit is contained in:
parent
aade2eedb9
commit
3e12f83732
@ -4,9 +4,19 @@ import "net/url"
|
||||
|
||||
// LocationWithTrailingSlash returns the URL in a relative format, with a trailing slash.
|
||||
func LocationWithTrailingSlash(u *url.URL) string {
|
||||
l := "./" + u.Path[1:] + "/"
|
||||
l := "./"
|
||||
|
||||
for i := 1; i < len(u.Path); i++ {
|
||||
if u.Path[i] == '/' {
|
||||
l += "../"
|
||||
}
|
||||
}
|
||||
|
||||
l += u.Path[1:] + "/"
|
||||
|
||||
if u.RawQuery != "" {
|
||||
l += "?" + u.RawQuery
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
@ -28,6 +28,13 @@ func TestLocationWithTrailingSlash(t *testing.T) {
|
||||
},
|
||||
"./www.example.com/",
|
||||
},
|
||||
{
|
||||
"slashes in path",
|
||||
&url.URL{
|
||||
Path: "/my/path",
|
||||
},
|
||||
"./../my/path/",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
require.Equal(t, ca.loc, LocationWithTrailingSlash(ca.url))
|
||||
|
Loading…
Reference in New Issue
Block a user