Commit 6267eb7
Fix panic in log with empty header
Previously using `l.SetHeader("")` would panic with:
--- FAIL: TestEmptyHeader (0.00s)
panic: runtime error: index out of range [-1] [recovered]
panic: runtime error: index out of range [-1]
goroutine 18 [running]:
github.com/labstack/gommon/log.(*Logger).log(0xc00014e990, 0x1, {0x5fb505, 0xd}, {0x0, 0x0, 0x0})
/home/martin/src/gommon/log/log.go:394 +0x615
github.com/labstack/gommon/log.(*Logger).Debugf(...)
/home/martin/src/gommon/log/log.go:158
github.com/labstack/gommon/log.TestEmptyHeader(0xc000129860?)
/home/martin/src/gommon/log/log_test.go:128 +0xb1
This adds a check for that. It also checks if there is any content
before writing a space in the "Text header" else branch so you don't end
up with " my message".1 parent 64116ba commit 6267eb7
2 files changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
408 | 410 | | |
409 | 411 | | |
410 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
122 | 132 | | |
123 | 133 | | |
124 | 134 | | |
| |||
0 commit comments