hc icon indicating copy to clipboard operation
hc copied to clipboard

NewIPTransport add validation

Open xxandev opened this issue 4 years ago • 3 comments

(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)
...

xxandev avatar Feb 12 '21 12:02 xxandev

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.

brutella avatar Mar 09 '21 13:03 brutella

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

xxandev avatar Mar 11 '21 10:03 xxandev

Related: #192

joeshaw avatar Apr 30 '21 19:04 joeshaw