|
5 | 5 | "bytes"
|
6 | 6 | "context"
|
7 | 7 | "encoding/csv"
|
| 8 | + e "errors" |
8 | 9 | "fmt"
|
9 | 10 | "mime"
|
10 | 11 | "mime/multipart"
|
@@ -219,6 +220,17 @@ func getFileRecordsFromZip(multipartFile multipart.File, fileHeader *multipart.F
|
219 | 220 | continue
|
220 | 221 | }
|
221 | 222 | fullName := srcFile.FileHeader.Name // full name with relative path to zip file
|
| 223 | + if srcFile.NonUTF8 { |
| 224 | + utf8NameByte, err := utils.ConvertToUtf8([]byte(fullName)) |
| 225 | + if err != nil { |
| 226 | + if e.Is(err, utils.ErrUnknownEncoding) { |
| 227 | + return nil, e.New("the file name contains unrecognized characters. Please ensure the file name is encoded in UTF-8 or use an English file name") |
| 228 | + } |
| 229 | + return nil, err |
| 230 | + } else { |
| 231 | + fullName = string(utf8NameByte) |
| 232 | + } |
| 233 | + } |
222 | 234 | if strings.HasSuffix(fullName, ".sql") {
|
223 | 235 | auditFiles = append(auditFiles, model.NewFileRecord(0, execOrder, fullName, model.GenUniqueFileName()))
|
224 | 236 | execOrder++
|
@@ -323,6 +335,12 @@ func CreateAndAuditTask(c echo.Context) error {
|
323 | 335 |
|
324 | 336 | task.ExecMode = req.ExecMode
|
325 | 337 | task.FileOrderMethod = req.FileOrderMethod
|
| 338 | + |
| 339 | + err = convertSQLSourceEncodingFromTask(task) |
| 340 | + if err != nil { |
| 341 | + return controller.JSONBaseErrorReq(c, err) |
| 342 | + } |
| 343 | + |
326 | 344 | taskGroup := model.TaskGroup{Tasks: []*model.Task{task}}
|
327 | 345 | err = s.Save(&taskGroup)
|
328 | 346 | if err != nil {
|
@@ -353,6 +371,23 @@ func CreateAndAuditTask(c echo.Context) error {
|
353 | 371 | })
|
354 | 372 | }
|
355 | 373 |
|
| 374 | +func convertSQLSourceEncodingFromTask(task *model.Task) error { |
| 375 | + for _, sql := range task.ExecuteSQLs { |
| 376 | + if sql.SourceFile == "" { |
| 377 | + continue |
| 378 | + } |
| 379 | + utf8NameByte, err := utils.ConvertToUtf8([]byte(sql.SourceFile)) |
| 380 | + if err != nil { |
| 381 | + if e.Is(err, utils.ErrUnknownEncoding) { |
| 382 | + return e.New("the file name contains unrecognized characters. Please ensure the file name is encoded in UTF-8 or use an English file name") |
| 383 | + } |
| 384 | + return err |
| 385 | + } |
| 386 | + sql.SourceFile = string(utf8NameByte) |
| 387 | + } |
| 388 | + return nil |
| 389 | +} |
| 390 | + |
356 | 391 | // @Summary 获取Sql扫描任务信息
|
357 | 392 | // @Description get task
|
358 | 393 | // @Tags task
|
@@ -987,6 +1022,13 @@ func AuditTaskGroupV1(c echo.Context) error {
|
987 | 1022 | }
|
988 | 1023 | }
|
989 | 1024 |
|
| 1025 | + for _, task := range taskGroup.Tasks { |
| 1026 | + err = convertSQLSourceEncodingFromTask(task) |
| 1027 | + if err != nil { |
| 1028 | + return controller.JSONBaseErrorReq(c, err) |
| 1029 | + } |
| 1030 | + } |
| 1031 | + |
990 | 1032 | if err := s.Save(taskGroup); err != nil {
|
991 | 1033 | return controller.JSONBaseErrorReq(c, err)
|
992 | 1034 | }
|
|
0 commit comments