mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
base: mark URLs with opaque data or fragments as invalid
This commit is contained in:
@@ -32,6 +32,14 @@ func ParseURL(s string) (*URL, error) {
|
|||||||
return nil, fmt.Errorf("unsupported scheme '%s'", u.Scheme)
|
return nil, fmt.Errorf("unsupported scheme '%s'", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if u.Opaque != "" {
|
||||||
|
return nil, fmt.Errorf("URLs with opaque data are not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
if u.Fragment != "" {
|
||||||
|
return nil, fmt.Errorf("URLs with fragments are not supported")
|
||||||
|
}
|
||||||
|
|
||||||
return (*URL)(u), nil
|
return (*URL)(u), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +61,6 @@ func (u *URL) String() string {
|
|||||||
func (u *URL) Clone() *URL {
|
func (u *URL) Clone() *URL {
|
||||||
return (*URL)(&url.URL{
|
return (*URL)(&url.URL{
|
||||||
Scheme: u.Scheme,
|
Scheme: u.Scheme,
|
||||||
Opaque: u.Opaque,
|
|
||||||
User: u.User,
|
User: u.User,
|
||||||
Host: u.Host,
|
Host: u.Host,
|
||||||
Path: u.Path,
|
Path: u.Path,
|
||||||
@@ -67,7 +74,6 @@ func (u *URL) Clone() *URL {
|
|||||||
func (u *URL) CloneWithoutCredentials() *URL {
|
func (u *URL) CloneWithoutCredentials() *URL {
|
||||||
return (*URL)(&url.URL{
|
return (*URL)(&url.URL{
|
||||||
Scheme: u.Scheme,
|
Scheme: u.Scheme,
|
||||||
Opaque: u.Opaque,
|
|
||||||
Host: u.Host,
|
Host: u.Host,
|
||||||
Path: u.Path,
|
Path: u.Path,
|
||||||
RawPath: u.RawPath,
|
RawPath: u.RawPath,
|
||||||
|
@@ -6,6 +6,27 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestURLInvalid(t *testing.T) {
|
||||||
|
for _, ca := range []struct {
|
||||||
|
name string
|
||||||
|
enc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"with opaque data",
|
||||||
|
"rtsp:opaque?query",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"with fragment",
|
||||||
|
"rtsp://localhost:8554/teststream#fragment",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
_, err := ParseURL(ca.enc)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestURLRTSPPath(t *testing.T) {
|
func TestURLRTSPPath(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
u *URL
|
u *URL
|
||||||
|
Reference in New Issue
Block a user