mirror of https://github.com/sirupsen/logrus.git
Merge branch 'disable-quotes' of https://github.com/thlacroix/logrus into thlacroix-disable-quotes
This commit is contained in:
commit
4d96c600d9
|
@ -37,6 +37,9 @@ type TextFormatter struct {
|
||||||
// Force quoting of all values
|
// Force quoting of all values
|
||||||
ForceQuote bool
|
ForceQuote bool
|
||||||
|
|
||||||
|
// DisableQuote disables quoting for all values
|
||||||
|
DisableQuote bool
|
||||||
|
|
||||||
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
|
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
|
||||||
EnvironmentOverrideColors bool
|
EnvironmentOverrideColors bool
|
||||||
|
|
||||||
|
@ -292,6 +295,9 @@ func (f *TextFormatter) needsQuoting(text string) bool {
|
||||||
if f.QuoteEmptyFields && len(text) == 0 {
|
if f.QuoteEmptyFields && len(text) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if f.DisableQuote {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, ch := range text {
|
for _, ch := range text {
|
||||||
if !((ch >= 'a' && ch <= 'z') ||
|
if !((ch >= 'a' && ch <= 'z') ||
|
||||||
(ch >= 'A' && ch <= 'Z') ||
|
(ch >= 'A' && ch <= 'Z') ||
|
||||||
|
|
|
@ -59,6 +59,7 @@ func TestQuoting(t *testing.T) {
|
||||||
checkQuoting(false, "foo@bar")
|
checkQuoting(false, "foo@bar")
|
||||||
checkQuoting(false, "foobar^")
|
checkQuoting(false, "foobar^")
|
||||||
checkQuoting(false, "+/-_^@f.oobar")
|
checkQuoting(false, "+/-_^@f.oobar")
|
||||||
|
checkQuoting(true, "foo\n\rbar")
|
||||||
checkQuoting(true, "foobar$")
|
checkQuoting(true, "foobar$")
|
||||||
checkQuoting(true, "&foobar")
|
checkQuoting(true, "&foobar")
|
||||||
checkQuoting(true, "x y")
|
checkQuoting(true, "x y")
|
||||||
|
@ -70,13 +71,30 @@ func TestQuoting(t *testing.T) {
|
||||||
tf.QuoteEmptyFields = true
|
tf.QuoteEmptyFields = true
|
||||||
checkQuoting(true, "")
|
checkQuoting(true, "")
|
||||||
checkQuoting(false, "abcd")
|
checkQuoting(false, "abcd")
|
||||||
|
checkQuoting(true, "foo\n\rbar")
|
||||||
checkQuoting(true, errors.New("invalid argument"))
|
checkQuoting(true, errors.New("invalid argument"))
|
||||||
|
|
||||||
// Test forcing quotes.
|
// Test forcing quotes.
|
||||||
tf.ForceQuote = true
|
tf.ForceQuote = true
|
||||||
checkQuoting(true, "")
|
checkQuoting(true, "")
|
||||||
checkQuoting(true, "abcd")
|
checkQuoting(true, "abcd")
|
||||||
|
checkQuoting(true, "foo\n\rbar")
|
||||||
checkQuoting(true, errors.New("invalid argument"))
|
checkQuoting(true, errors.New("invalid argument"))
|
||||||
|
|
||||||
|
// Test forcing quotes when also disabling them.
|
||||||
|
tf.DisableQuote = true
|
||||||
|
checkQuoting(true, "")
|
||||||
|
checkQuoting(true, "abcd")
|
||||||
|
checkQuoting(true, "foo\n\rbar")
|
||||||
|
checkQuoting(true, errors.New("invalid argument"))
|
||||||
|
|
||||||
|
// Test disabling quotes
|
||||||
|
tf.ForceQuote = false
|
||||||
|
tf.QuoteEmptyFields = false
|
||||||
|
checkQuoting(false, "")
|
||||||
|
checkQuoting(false, "abcd")
|
||||||
|
checkQuoting(false, "foo\n\rbar")
|
||||||
|
checkQuoting(false, errors.New("invalid argument"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEscaping(t *testing.T) {
|
func TestEscaping(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue