forked from mirror/logrus
Adds flag to disable quotes in TextFormatter
This commit is contained in:
parent
91ef3ab5d5
commit
c7455de10a
|
@ -37,6 +37,9 @@ type TextFormatter struct {
|
|||
// Force quoting of all values
|
||||
ForceQuote bool
|
||||
|
||||
// DisableQuote disables quoting for all values
|
||||
DisableQuote bool
|
||||
|
||||
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
|
||||
EnvironmentOverrideColors bool
|
||||
|
||||
|
@ -292,6 +295,9 @@ func (f *TextFormatter) needsQuoting(text string) bool {
|
|||
if f.QuoteEmptyFields && len(text) == 0 {
|
||||
return true
|
||||
}
|
||||
if f.DisableQuote {
|
||||
return false
|
||||
}
|
||||
for _, ch := range text {
|
||||
if !((ch >= 'a' && ch <= 'z') ||
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
|
|
|
@ -66,6 +66,14 @@ func TestQuoting(t *testing.T) {
|
|||
checkQuoting(false, errors.New("invalid"))
|
||||
checkQuoting(true, errors.New("invalid argument"))
|
||||
|
||||
// Test for quoting disabled
|
||||
tf.DisableQuote = true
|
||||
checkQuoting(false, "")
|
||||
checkQuoting(false, "abcd")
|
||||
checkQuoting(false, "foo\n\rbar")
|
||||
checkQuoting(false, errors.New("invalid argument"))
|
||||
tf.DisableQuote = false
|
||||
|
||||
// Test for quoting empty fields.
|
||||
tf.QuoteEmptyFields = true
|
||||
checkQuoting(true, "")
|
||||
|
|
Loading…
Reference in New Issue