diff --git a/libnetwork/config/config.go b/libnetwork/config/config.go index bb93d981b1..1935e1657b 100644 --- a/libnetwork/config/config.go +++ b/libnetwork/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/libnetwork/config/config_test.go b/libnetwork/config/config_test.go index 0d93819545..876078687f 100644 --- a/libnetwork/config/config_test.go +++ b/libnetwork/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/libnetwork/controller.go b/libnetwork/controller.go index d84f5d4d52..a2a861feba 100644 --- a/libnetwork/controller.go +++ b/libnetwork/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)