From f22df7f0127b448a27a4b8e7863fd79c1b82e877 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 3 Jan 2025 16:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=8F=8A=E6=9B=B4=E6=96=B0=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A2=9E=E5=88=A0=E6=94=B9?= =?UTF-8?q?=E6=9F=A5=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8A=9F=E8=83=BD.=E6=B7=BB=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/fileService.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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 { //创建文件