diff --git a/config/config.go b/config/config.go index bb93d98..1935e16 100644 --- a/config/config.go +++ b/config/config.go @@ -109,7 +109,7 @@ func (c *Config) ProcessOptions(options ...Option) { // IsValidName validates configuration objects supported by libnetwork func IsValidName(name string) bool { - if name == "" || strings.Contains(name, ".") { + if strings.TrimSpace(name) == "" || strings.Contains(name, ".") { return false } return true diff --git a/config/config_test.go b/config/config_test.go index 0d93819..8760786 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -49,6 +49,9 @@ func TestValidName(t *testing.T) { if IsValidName("") { t.Fatal("Name validation succeeds for a case when it is expected to fail") } + if IsValidName(" ") { + t.Fatal("Name validation succeeds for a case when it is expected to fail") + } if IsValidName("name.with.dots") { t.Fatal("Name validation succeeds for a case when it is expected to fail") } diff --git a/controller.go b/controller.go index d84f5d4..a2a861f 100644 --- a/controller.go +++ b/controller.go @@ -204,11 +204,11 @@ func (c *controller) ConfigureNetworkDriver(networkType string, options map[stri } func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error { - c.Lock() if !config.IsValidName(networkType) { - c.Unlock() return ErrInvalidName(networkType) } + + c.Lock() if _, ok := c.drivers[networkType]; ok { c.Unlock() return driverapi.ErrActiveRegistration(networkType)