server: fix reading with ffplay and stateless ipv6

This commit is contained in:
aler9
2022-04-21 13:15:11 +02:00
parent d2380aeed1
commit 1e612f2443
2 changed files with 28 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package base
import (
"fmt"
"net/url"
"strings"
)
// URL is a RTSP URL.
@@ -12,6 +13,9 @@ type URL url.URL
// ParseURL parses a RTSP URL.
func ParseURL(s string) (*URL, error) {
s = strings.ReplaceAll(s, "%25", "%")
s = strings.ReplaceAll(s, "%", "%25")
u, err := url.Parse(s)
if err != nil {
return nil, err

View File

@@ -14,6 +14,30 @@ func mustParseURL(s string) *URL {
return u
}
func TestURLParse(t *testing.T) {
for _, ca := range []struct {
name string
enc string
u *URL
}{
{
"ipv6 stateless",
`rtsp://[fe80::a8f4:3219:f33e:a072%wl0]:8554/proxied`,
&URL{
Scheme: "rtsp",
Host: "[fe80::a8f4:3219:f33e:a072%wl0]:8554",
Path: "/proxied",
},
},
} {
t.Run(ca.name, func(t *testing.T) {
u, err := ParseURL(ca.enc)
require.NoError(t, err)
require.Equal(t, ca.u, u)
})
}
}
func TestURLParseErrors(t *testing.T) {
for _, ca := range []struct {
name string