mirror of https://bitbucket.org/ausocean/av.git
Merged in better-rtmp-url-checking (pull request #172)
Made parseURL() more robust. Approved-by: Saxon Milton <saxon.milton@gmail.com> Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
commit
c102fa06a1
|
@ -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