From 759b7ad4b8ebab321b4d030201ad4328e9a692ee Mon Sep 17 00:00:00 2001 From: Vinzenz Feenstra Date: Wed, 2 Nov 2016 20:48:45 +0100 Subject: [PATCH] Fixes go-yaml/yaml#214 - New option to allow setting strict boolean mode Signed-off-by: Vinzenz Feenstra --- decode.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/decode.go b/decode.go index 17a5440f..7da6c457 100644 --- a/decode.go +++ b/decode.go @@ -192,8 +192,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. @@ -222,6 +223,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 @@ -433,6 +439,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 {