Engine: empty job names are illegal, catchall or not
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes) Upstream-commit: 3b73c26194836c1e2b737146a5b0c840226c65d2 Component: engine
This commit is contained in:
@ -122,7 +122,8 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
||||
// Catchall is shadowed by specific Register.
|
||||
if handler, exists := eng.handlers[name]; exists {
|
||||
job.handler = handler
|
||||
} else if eng.catchall != nil {
|
||||
} else if eng.catchall != nil && name != "" {
|
||||
// empty job names are illegal, catchall or not.
|
||||
job.handler = eng.catchall
|
||||
}
|
||||
return job
|
||||
|
||||
@ -133,3 +133,19 @@ func TestParseJob(t *testing.T) {
|
||||
t.Fatalf("Job was not called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatchallEmptyName(t *testing.T) {
|
||||
eng := New()
|
||||
var called bool
|
||||
eng.RegisterCatchall(func(job *Job) Status {
|
||||
called = true
|
||||
return StatusOK
|
||||
})
|
||||
err := eng.Job("").Run()
|
||||
if err == nil {
|
||||
t.Fatalf("Engine.Job(\"\").Run() should return an error")
|
||||
}
|
||||
if called {
|
||||
t.Fatalf("Engine.Job(\"\").Run() should return an error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user