fix: variable name should start with a letter or underscore

This commit is contained in:
debugtalk
2021-09-29 12:00:11 +08:00
parent e54ddfebec
commit e007d0dc24
2 changed files with 90 additions and 15 deletions

View File

@@ -42,7 +42,8 @@ func parseData(raw interface{}, variablesMapping map[string]interface{}) interfa
}
var (
regexCompileVariable = regexp.MustCompile(`\$\{(\w+)\}|\$(\w+)`) // parse ${var} or $var
regexVariable = `[a-zA-Z_]\w*` // variable name should start with a letter or underscore
regexCompileVariable = regexp.MustCompile(fmt.Sprintf(`\$\{(%s)\}|\$(%s)`, regexVariable, regexVariable)) // parse ${var} or $var
)
// parseString parse string with variables
@@ -87,6 +88,9 @@ func parseString(raw string, variablesMapping map[string]interface{}) interface{
log.Printf("[parseString] parsedString: %v, matchStartPosition: %v", parsedString, matchStartPosition)
continue
}
parsedString += remainedString
break
}
return parsedString