Fix panic in log with empty header#51
Merged
Merged
Conversation
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".
Codecov Report
@@ Coverage Diff @@
## master #51 +/- ##
==========================================
+ Coverage 60.64% 60.70% +0.06%
==========================================
Files 6 6
Lines 625 626 +1
==========================================
+ Hits 379 380 +1
Misses 242 242
Partials 4 4
Continue to review full report at Codecov.
|
Contributor
|
@arp242 Thank you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously using
l.SetHeader("")would panic with: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".