Skip to content

Commit

Permalink
hls, webrtc: fix appending slash to paths that contain slashes (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Dec 1, 2023
1 parent aade2ee commit 3e12f83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/protocols/httpserv/location_with_trailing_slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3e12f83

Please sign in to comment.