From 9a6b5ab73a025401d2dd83533a0d103fb5d13dc2 Mon Sep 17 00:00:00 2001 From: Astatin Date: Sun, 13 Oct 2024 09:01:07 +0900 Subject: Disallow special characters in label names --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index 1968fb2..27bdf87 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "regexp" "strings" ) @@ -52,6 +53,15 @@ func firstPass( parts := strings.Split(line, ":") for _, label := range parts[:len(parts)-1] { label = strings.TrimSpace(strings.ToUpper(label)) + isCharsetAllowed := regexp.MustCompile(`^[a-zA-Z0-9_-]*$`).MatchString(label) + if !isCharsetAllowed { + return nil, fmt.Errorf( + "File %s, line %d:\nLabel \"%s\" contains special characters. Only alphanumeric, dashes and underscores are allowed", + input_file_name, + line_nb+1, + label, + ) + } if _, ok := state.Labels[label]; ok { return nil, fmt.Errorf( "File %s, line %d:\nLabel %s is already defined", -- cgit v1.2.3-70-g09d2