Skip to content

Commit

Permalink
Fix encoding of maps inside sequences.
Browse files Browse the repository at this point in the history
Reported by Ahmet Alp Balkan.
  • Loading branch information
niemeyer committed Apr 9, 2019
1 parent 389beb8 commit fc85683
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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) {
return false
}
Expand Down
56 changes: 56 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
yaml.Node{
Expand Down

0 comments on commit fc85683

Please sign in to comment.