diff --git a/conf/lex.go b/conf/lex.go index 3f6ae1c6..8a7ce5f7 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -684,8 +684,10 @@ func lexMapEnd(lx *lexer) stateFn { // Checks if the unquoted string was actually a boolean func (lx *lexer) isBool() bool { - str := lx.input[lx.start:lx.pos] - return str == "true" || str == "false" || str == "TRUE" || str == "FALSE" + str := strings.ToLower(lx.input[lx.start:lx.pos]) + return str == "true" || str == "false" || + str == "on" || str == "off" || + str == "yes" || str == "no" } // Check if the unquoted string is a variable reference, starting with $. diff --git a/conf/parse.go b/conf/parse.go index fa7292db..32767c48 100644 --- a/conf/parse.go +++ b/conf/parse.go @@ -183,10 +183,10 @@ func (p *parser) processItem(it item) error { } p.setValue(num) case itemBool: - switch it.val { - case "true": + switch strings.ToLower(it.val) { + case "true", "yes", "on": p.setValue(true) - case "false": + case "false", "no", "off": p.setValue(false) default: return fmt.Errorf("Expected boolean value, but got '%s'.", it.val) diff --git a/conf/parse_test.go b/conf/parse_test.go index d675cca5..6992c113 100644 --- a/conf/parse_test.go +++ b/conf/parse_test.go @@ -35,6 +35,17 @@ func TestSimpleTopLevel(t *testing.T) { test(t, "foo='1'; bar=2.2; baz=true; boo=22", ex) } +func TestBools(t *testing.T) { + ex := map[string]interface{}{ + "foo": true, + } + test(t, "foo=true", ex) + test(t, "foo=TRUE", ex) + test(t, "foo=true", ex) + test(t, "foo=yes", ex) + test(t, "foo=on", ex) +} + var varSample = ` index = 22 foo = $index