Просмотр исходного кода

Fix encoding of maps inside sequences.

Reported by Ahmet Alp Balkan.
Gustavo Niemeyer 7 лет назад
Родитель
Сommit
fc85683543
2 измененных файлов с 57 добавлено и 1 удалено
  1. 1 1
      emitterc.go
  2. 56 0
      node_test.go

+ 1 - 1
emitterc.go

@@ -764,7 +764,7 @@ func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_ev
 	if !yaml_emitter_process_head_comment(emitter) {
 	if !yaml_emitter_process_head_comment(emitter) {
 		return false
 		return false
 	}
 	}
-	if emitter.states[len(emitter.states)-1] != yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE {
+	if !first || emitter.states[len(emitter.states)-1] != yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE {
 		if !yaml_emitter_write_indent(emitter) {
 		if !yaml_emitter_write_indent(emitter) {
 			return false
 			return false
 		}
 		}

+ 56 - 0
node_test.go

@@ -436,6 +436,62 @@ var nodeTests = []struct {
 				}},
 				}},
 			}},
 			}},
 		},
 		},
+	}, {
+		"a:\n- b: c\n  d: e\n",
+		yaml.Node{
+			Kind:   yaml.DocumentNode,
+			Line:   1,
+			Column: 1,
+			Content: []*yaml.Node{{
+				Kind:   yaml.MappingNode,
+				Tag:    "!!map",
+				Line:   1,
+				Column: 1,
+				Content: []*yaml.Node{{
+					Kind:   yaml.ScalarNode,
+					Value:  "a",
+					Tag:    "!!str",
+					Line:   1,
+					Column: 1,
+				}, {
+					Kind:   yaml.SequenceNode,
+					Tag:    "!!seq",
+					Line:   2,
+					Column: 1,
+					Content: []*yaml.Node{{
+						Kind:   yaml.MappingNode,
+						Tag:    "!!map",
+						Line:   2,
+						Column: 3,
+						Content: []*yaml.Node{{
+							Kind:   yaml.ScalarNode,
+							Value:  "b",
+							Tag:    "!!str",
+							Line:   2,
+							Column: 3,
+						}, {
+							Kind:   yaml.ScalarNode,
+							Value:  "c",
+							Tag:    "!!str",
+							Line:   2,
+							Column: 6,
+						}, {
+							Kind:   yaml.ScalarNode,
+							Value:  "d",
+							Tag:    "!!str",
+							Line:   3,
+							Column: 3,
+						}, {
+							Kind:   yaml.ScalarNode,
+							Value:  "e",
+							Tag:    "!!str",
+							Line:   3,
+							Column: 6,
+						}},
+					}},
+				}},
+			}},
+		},
 	}, {
 	}, {
 		"- a\n- b\n",
 		"- a\n- b\n",
 		yaml.Node{
 		yaml.Node{