Fix encoding error with bare hyphen
diff --git a/decode_test.go b/decode_test.go index 9b2a263..472fa76 100644 --- a/decode_test.go +++ b/decode_test.go
@@ -393,6 +393,7 @@ {"v:\n- [A,", "YAML error: line 2: did not find expected node content"}, {"a: *b\n", "YAML error: Unknown anchor 'b' referenced"}, {"a: &a\n b: *a\n", "YAML error: Anchor 'a' value contains itself"}, + {"value: -", "YAML error: block sequence entries are not allowed in this context"}, } func (s *S) TestUnmarshalErrors(c *C) {
diff --git a/emitterc.go b/emitterc.go index ac63f28..8fe2363 100644 --- a/emitterc.go +++ b/emitterc.go
@@ -1012,7 +1012,7 @@ return true } - if (value[0] == '-' && value[1] == '-' && value[2] == '-') || (value[0] == '.' && value[1] == '.' && value[2] == '.') { + if len(value) == 3 && ((value[0] == '-' && value[1] == '-' && value[2] == '-') || (value[0] == '.' && value[1] == '.' && value[2] == '.')) { block_indicators = true flow_indicators = true }
diff --git a/encode_test.go b/encode_test.go index 5d16426..9ef7c16 100644 --- a/encode_test.go +++ b/encode_test.go
@@ -93,6 +93,9 @@ }, { map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}}, "a:\n b: c\n", + }, { + map[string]interface{}{"a": "-"}, + "a: '-'\n", }, // Simple values.