diff options
author | Astatin <[email protected]> | 2024-10-13 09:01:07 +0900 |
---|---|---|
committer | Astatin <[email protected]> | 2024-10-13 09:01:07 +0900 |
commit | 9a6b5ab73a025401d2dd83533a0d103fb5d13dc2 (patch) | |
tree | 26bb0964426b32102309a4fd0d34b71d75fd6578 | |
parent | e543410ac3b4787b9922ef065a703482c3aeeb1f (diff) |
Disallow special characters in label names
-rw-r--r-- | main.go | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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", |