mirror of https://bitbucket.org/ausocean/av.git
Made parseURL() more robust.
This commit is contained in:
parent
30711a54fa
commit
61c1d99c43
|
@ -75,20 +75,16 @@ func parseURL(addr string) (protocol int32, host string, port uint16, app, playp
|
|||
port = uint16(pi)
|
||||
}
|
||||
|
||||
if !path.IsAbs(u.Path) {
|
||||
return protocol, host, port, app, playpath, nil
|
||||
}
|
||||
|
||||
elems := strings.SplitN(u.Path[1:], "/", 3)
|
||||
app = elems[0]
|
||||
if len(elems[len(elems)-1]) == 0 {
|
||||
elems = elems[:len(elems)-1]
|
||||
}
|
||||
if app == "" || len(elems) < 2 {
|
||||
if len(u.Path) < 1 || !path.IsAbs(u.Path) {
|
||||
return protocol, host, port, app, playpath, errInvalidURL
|
||||
}
|
||||
|
||||
elems := strings.SplitN(u.Path[1:], "/", 3)
|
||||
if len(elems) < 2 || elems[0] == "" || elems[1] == "" {
|
||||
return protocol, host, port, app, playpath, errInvalidURL
|
||||
}
|
||||
app = elems[0]
|
||||
playpath = path.Join(elems[1:]...)
|
||||
|
||||
switch ext := path.Ext(playpath); ext {
|
||||
case ".f4v", ".mp4":
|
||||
playpath = playpath[:len(playpath)-len(ext)]
|
||||
|
|
|
@ -41,7 +41,7 @@ var parseURLTests = []struct {
|
|||
}{
|
||||
{
|
||||
url: "rtmp://addr",
|
||||
wantHost: "addr",
|
||||
wantErr: errInvalidURL,
|
||||
},
|
||||
{
|
||||
url: "rtmp://addr/",
|
||||
|
|
Loading…
Reference in New Issue