Skip to content

Commit

Permalink
Fixes #214 - New option to allow setting strict boolean mode
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
  • Loading branch information
Vinzenz Feenstra committed Nov 2, 2016
1 parent f80922e commit b373073
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions decode.go
Expand Up @@ -193,8 +193,9 @@ type Decoder struct {
}

type DecoderOptions struct {
Strict bool
Recursive bool
Strict bool
Recursive bool
StrictBool bool
}

// NewDecoder creates and initializes a new Decoder struct.
Expand Down Expand Up @@ -223,6 +224,11 @@ func (d *Decoder) SetStrict(strict bool) {
d.options.Strict = strict
}

// SetStrict puts the decoder to strict boolean mode (According to the 1.2 YAML Spec)
func (d *Decoder) SetStrictBool(strict bool) {
d.options.StrictBool = strict
}

// SetAllowRecursive allows to enable / disable the recursive parsing feature
func (d *Decoder) SetAllowRecursive(recursive bool) {
d.options.Recursive = recursive
Expand Down Expand Up @@ -434,6 +440,10 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
failf("!!binary value contains invalid base64 data")
}
resolved = string(data)
} else if d.options.StrictBool && tag == yaml_BOOL_TAG {
if resolved != "true" && resolved != "false" {
tag = yaml_STR_TAG
}
}
}
if resolved == nil {
Expand Down

0 comments on commit b373073

Please sign in to comment.