Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
| ... | ... |
@@ -122,7 +122,8 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
| 122 | 122 |
// Catchall is shadowed by specific Register. |
| 123 | 123 |
if handler, exists := eng.handlers[name]; exists {
|
| 124 | 124 |
job.handler = handler |
| 125 |
- } else if eng.catchall != nil {
|
|
| 125 |
+ } else if eng.catchall != nil && name != "" {
|
|
| 126 |
+ // empty job names are illegal, catchall or not. |
|
| 126 | 127 |
job.handler = eng.catchall |
| 127 | 128 |
} |
| 128 | 129 |
return job |
| ... | ... |
@@ -133,3 +133,19 @@ func TestParseJob(t *testing.T) {
|
| 133 | 133 |
t.Fatalf("Job was not called")
|
| 134 | 134 |
} |
| 135 | 135 |
} |
| 136 |
+ |
|
| 137 |
+func TestCatchallEmptyName(t *testing.T) {
|
|
| 138 |
+ eng := New() |
|
| 139 |
+ var called bool |
|
| 140 |
+ eng.RegisterCatchall(func(job *Job) Status {
|
|
| 141 |
+ called = true |
|
| 142 |
+ return StatusOK |
|
| 143 |
+ }) |
|
| 144 |
+ err := eng.Job("").Run()
|
|
| 145 |
+ if err == nil {
|
|
| 146 |
+ t.Fatalf("Engine.Job(\"\").Run() should return an error")
|
|
| 147 |
+ } |
|
| 148 |
+ if called {
|
|
| 149 |
+ t.Fatalf("Engine.Job(\"\").Run() should return an error")
|
|
| 150 |
+ } |
|
| 151 |
+} |