aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-10-13 09:01:07 +0900
committerAstatin <[email protected]>2024-10-13 09:01:07 +0900
commit9a6b5ab73a025401d2dd83533a0d103fb5d13dc2 (patch)
tree26bb0964426b32102309a4fd0d34b71d75fd6578
parente543410ac3b4787b9922ef065a703482c3aeeb1f (diff)
Disallow special characters in label names
-rw-r--r--main.go10
1 files changed, 10 insertions, 0 deletions
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",