hc
hc copied to clipboard
NewIPTransport add validation
(a-z, A-Z, 0-9, \s, -) if other characters are used, the accessory is started but cannot be added
Сurrent:
func NewIPTransport(config Config, a *accessory.Accessory, as ...*accessory.Accessory) (*ipTransport, error) {
name := a.Info.Name.GetValue()
if len(name) == 0 {
log.Info.Panic("Invalid empty name for first accessory")
}
cfg := defaultConfig(name)
...
Desired:
func NewIPTransport(config Config, a *accessory.Accessory, as ...*accessory.Accessory) (*ipTransport, error) {
name := a.Info.Name.GetValue()
if len(name) == 0 {
return nil, errors.New("accessory name cannot be empty")
}
validName := regexp.MustCompile(`^[a-zA-Z0-9\s\-]+$`).MatchString
if validName(name) {
return nil, errors.New("invalid accessory name, should only contain (a-z, A-Z, 0-9, \\s, -)")
}
cfg := defaultConfig(name)
...
I've just tried to add an accessory with the name Brücke
which contains the umlaut ö
. The bridge shows up as Brucke
because RemoveAccentsFromString()
does its job to convert ö
to o
. I was able to add it to HomeKit with no problems.
doesn't add, in my home accessory.Info{Name: "Люстра", SerialNumber: "test1sw"} accessory.Info{Name: "#test", SerialNumber: "test2sw"} accessory.Info{Name: "测试", SerialNumber: "test3sw"} accessory.Info{Name: "@send mess", SerialNumber: "test4sw"} accessory.Info{Name: "switch 21/1", SerialNumber: "test5sw"}
https://github.com/alpr777/homekit/tree/main/example/switch
Related: #192