Browse Source

Engine: empty job names are illegal, catchall or not

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
Solomon Hykes 11 năm trước cách đây
mục cha
commit
3b73c26194
2 tập tin đã thay đổi với 18 bổ sung1 xóa
  1. 2 1
      engine/engine.go
  2. 16 0
      engine/engine_test.go

+ 2 - 1
engine/engine.go

@@ -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

+ 16 - 0
engine/engine_test.go

@@ -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")
+	}
+}