Merge pull request #330 from cuteLittleDevil/fix-cd-hls

[fix] 修复流名称中带.导致获取流名称错误的问题
pull/331/head
yoko 1 year ago committed by GitHub
commit cad540546e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -74,10 +74,9 @@ func (u *UrlContext) GetFileType() string {
func (u *UrlContext) calcFilenameAndTypeIfNeeded() {
if len(u.filenameWithoutType) == 0 || len(u.fileType) == 0 {
ss := strings.Split(u.LastItemOfPath, ".")
u.filenameWithoutType = ss[0]
if len(ss) > 1 {
u.fileType = ss[1]
if index := strings.LastIndex(u.LastItemOfPath, "."); index != -1 {
u.filenameWithoutType = u.LastItemOfPath[:index]
u.fileType = u.LastItemOfPath[index+1:]
}
}
}

@ -10,6 +10,7 @@ package base_test
import (
"fmt"
"regexp"
"testing"
"github.com/q191201771/lal/pkg/base"
@ -295,3 +296,27 @@ func testParseRtmpUrlCase2(t *testing.T) {
assert.Equal(t, "rtmp://xxx.net/vhall?vhost=thirdVhost?token=2A317D14t25690", tcUrlFn(ctx))
assert.Equal(t, "138521921", streamNameWithRawQueryFn(ctx))
}
func FuzzGetFilenameWithoutTypeAndGetFileType(f *testing.F) {
testcases := []string{
"playlist.m3u8",
"abcABC123.ts",
"192.168.1.68-1699692546341-2.ts",
}
for _, tc := range testcases {
f.Add(tc)
}
re := regexp.MustCompile(`.+\.[^.]+`)
f.Fuzz(func(t *testing.T, orig string) {
if !re.MatchString(orig) {
return
}
tmp := base.UrlContext{LastItemOfPath: orig}
filenameWithoutType := tmp.GetFilenameWithoutType()
fileType := tmp.GetFileType()
if orig != filenameWithoutType+"."+fileType {
t.Errorf("expected: [%s], actual: [%s.%s]",
orig, filenameWithoutType, fileType)
}
})
}

Loading…
Cancel
Save