فهرست منبع

goyaml: fix printing of bare hyphens

related to bug #1227952. Quote a bare hypen rather than treating it as
the start of a block.

R=wallyworld, jameinel
CC=
https://codereview.appspot.com/26430043
Dave Cheney 12 سال پیش
والد
کامیت
9c272e2574
3فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 1 0
      decode_test.go
  2. 1 1
      emitterc.go
  3. 3 0
      encode_test.go

+ 1 - 0
decode_test.go

@@ -402,6 +402,7 @@ var unmarshalErrorTests = []struct {
 	{"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) {

+ 1 - 1
emitterc.go

@@ -1012,7 +1012,7 @@ func yaml_emitter_analyze_scalar(emitter *yaml_emitter_t, value []byte) bool {
 		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
 	}

+ 3 - 0
encode_test.go

@@ -93,6 +93,9 @@ var marshalTests = []struct {
 	}, {
 		map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
 		"a:\n  b: c\n",
+	}, {
+		map[string]interface{}{"a": "-"},
+		"a: '-'\n",
 	},
 
 	// Simple values.