From 93fd6d5582d1c877bb518eadb168e7b5f4b03588 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 fed0487f..151e3bf0 100644 --- a/decode.go +++ b/decode.go @@ -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. @@ -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 @@ -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 {