Skip to content

Commit

Permalink
Fix comment handling around aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Apr 2, 2019
1 parent b53452e commit d22fc9e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ func (e *encoder) node(node *Node) {
e.emit()

case AliasNode:
// TODO This is lacking comment handling. Test and fix.
yaml_alias_event_initialize(&e.event, []byte(node.Value))
e.event.header_comment = []byte(node.Header)
e.event.inline_comment = []byte(node.Inline)
e.event.footer_comment = []byte(node.Footer)
e.emit()

case ScalarNode:
Expand Down
37 changes: 37 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,43 @@ var nodeTests = []struct {
}},
}},
},
}, {
"# DH1\n\n# DH2\n\n# HA1\n# HA2\n- &x la # IA\n# FA1\n# FA2\n\n# HB1\n# HB2\n- *x # IB\n# FB1\n# FB2\n\n# DF1\n\n# DF2\n",
yaml.Node{
Kind: yaml.DocumentNode,
Line: 7,
Column: 1,
Header: "# DH1\n\n# DH2",
Footer: "# DF1\n\n# DF2",
Children: []*yaml.Node{{
Kind: yaml.SequenceNode,
Tag: "!!seq",
Line: 7,
Column: 1,
Children: []*yaml.Node{
saveNode("x", &yaml.Node{
Kind: yaml.ScalarNode,
Tag: "!!str",
Line: 7,
Column: 3,
Value: "la",
Header: "# HA1\n# HA2",
Inline: "# IA",
Footer: "# FA1\n# FA2",
Anchor: "x",
}), {
Kind: yaml.AliasNode,
Line: 13,
Column: 3,
Value: "x",
Alias: dropNode("x"),
Header: "# HB1\n# HB2",
Inline: "# IB",
Footer: "# FB1\n# FB2",
},
},
}},
},
},
}

Expand Down
1 change: 1 addition & 0 deletions parserc.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, i
end_mark: token.end_mark,
anchor: token.value,
}
yaml_parser_set_event_comments(parser, event)
skip_token(parser)
return true
}
Expand Down
1 change: 0 additions & 1 deletion scannerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,6 @@ func yaml_parser_scan_block_scalar(parser *yaml_parser_t, token *yaml_token_t, l
}
}
if parser.buffer[parser.buffer_pos] == '#' {
// [Go] TODO This logic is untested and maybe broken.
if !yaml_parser_scan_inline_comment(parser, start_mark) {
return false
}
Expand Down

0 comments on commit d22fc9e

Please sign in to comment.