5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 18:01:17 +08:00

Fix taskfile in templates. Sanitize the project name

This commit is contained in:
Lea Anthony 2023-11-12 16:35:44 +11:00
parent eefeadc018
commit ae38d1e020
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 113 additions and 101 deletions

View File

@ -3,6 +3,7 @@ package commands
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"regexp"
"github.com/wailsapp/wails/v3/internal/flags" "github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/templates" "github.com/wailsapp/wails/v3/internal/templates"
@ -23,6 +24,8 @@ func Init(options *flags.Init) error {
return fmt.Errorf("please use the -n flag to specify a project name") return fmt.Errorf("please use the -n flag to specify a project name")
} }
options.ProjectName = sanitizeFileName(options.ProjectName)
if !templates.ValidTemplateName(options.TemplateName) { if !templates.ValidTemplateName(options.TemplateName) {
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName) return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName)
} }
@ -54,3 +57,12 @@ func printTemplates() error {
pterm.Println() pterm.Println()
return err return err
} }
func sanitizeFileName(fileName string) string {
// Regular expression to match non-allowed characters in file names
// You can adjust this based on the specific requirements of your file system
reg := regexp.MustCompile(`[^a-zA-Z0-9_.-]`)
// Replace matched characters with an underscore or any other safe character
return reg.ReplaceAllString(fileName, "_")
}