Vehicles: validate config name (#11210)
This commit is contained in:
parent
96ef894ccc
commit
26ed34081d
1 changed files with 7 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -68,6 +69,8 @@ var conf = globalConfig{
|
|||
},
|
||||
}
|
||||
|
||||
var nameRE = regexp.MustCompile(`^[a-zA-Z0-9_.:-]+$`)
|
||||
|
||||
type globalConfig struct {
|
||||
Network networkConfig
|
||||
Log string
|
||||
|
|
@ -271,6 +274,10 @@ func configureChargers(static []config.Named, names ...string) error {
|
|||
}
|
||||
|
||||
func vehicleInstance(cc config.Named) (api.Vehicle, error) {
|
||||
if !nameRE.MatchString(cc.Name) {
|
||||
return nil, fmt.Errorf("vehicle name must not contain special characters or spaces: %s", cc.Name)
|
||||
}
|
||||
|
||||
instance, err := vehicle.NewFromConfig(cc.Type, cc.Other)
|
||||
if err != nil {
|
||||
var ce *util.ConfigError
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue