mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Add more options for Booleans
This commit is contained in:
@@ -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 $.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user