diff --git a/service/fileService.go b/service/fileService.go index c604cec..3e8615a 100644 --- a/service/fileService.go +++ b/service/fileService.go @@ -9,6 +9,7 @@ import ( "mime/multipart" "os" "path" + "regexp" "time" "videoplayer/dao" "videoplayer/proto" @@ -83,6 +84,13 @@ func CreateConfigFile(req *proto.ConfigFileReq, userId int) error { } //查看系统中是否存在文件,不存在则创建 file := req.FilePath + "/" + req.FileName + //正则判断文件名是否合法 + pattern := `^/([^/:\*?]+/)*([^/:\*?]+)?$` + reg := regexp.MustCompile(pattern) + if reg.MatchString(file) == false { + err = fmt.Errorf("file path is invalid") + return err + } _, err = os.Stat(file) if err != nil { //创建文件