From cdd78af4bc37b17d913bf359de53b26facfa2932 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 6 Jun 2017 10:19:32 +1000 Subject: [PATCH] Fixed bug #11: Inability to set field to empty string --- yaml.go | 2 +- yaml_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/yaml.go b/yaml.go index 22a824e..9189291 100644 --- a/yaml.go +++ b/yaml.go @@ -195,7 +195,7 @@ func updateYaml(args []string) interface{} { func parseValue(argument string) interface{} { var value, err interface{} - var inQuotes = argument[0] == '"' + var inQuotes = len(argument) > 0 && argument[0] == '"' if !inQuotes { value, err = strconv.ParseFloat(argument, 64) if err == nil { diff --git a/yaml_test.go b/yaml_test.go index 60cc0a3..167a920 100644 --- a/yaml_test.go +++ b/yaml_test.go @@ -14,6 +14,7 @@ var parseValueTests = []struct { {"\"true\"", "true", "boolean as string"}, {"3.4", 3.4, "number"}, {"\"3.4\"", "3.4", "number as string"}, + {"", "", "empty string"}, } func TestParseValue(t *testing.T) {