Browse Source

改进 #251 的提交代码,增加越界判断

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
dbcd781d58
1 changed files with 7 additions and 1 deletions
  1. 7 1
      internal/pkg/my_util/util.go

+ 7 - 1
internal/pkg/my_util/util.go

@@ -118,7 +118,13 @@ func GetFileName(l *logrus.Logger, resp *http.Response) string {
 	contentDisposition := resp.Header.Get("Content-Disposition")
 	if len(contentDisposition) == 0 {
 		m := regexp.MustCompile(`^(.*/)?(?:$|(.+?)(?:(\.[^.]*$)|$))`).FindStringSubmatch(resp.Request.URL.String())
-		return m[2]+m[3]
+
+		if m == nil || len(m) < 4 {
+			l.Warningln("GetFileName.regexp.MustCompile.FindStringSubmatch", resp.Request.URL.String())
+			return ""
+		}
+
+		return m[2] + m[3]
 	}
 	re := regexp.MustCompile(`filename=["]*([^"]+)["]*`)
 	matched := re.FindStringSubmatch(contentDisposition)