Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newline bug #964

Open
wants to merge 4 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_eve
if !yaml_emitter_emit_node(emitter, event, true, false, false, false) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -557,7 +557,7 @@ func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_e
if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -602,7 +602,7 @@ func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_e
return false
}
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -643,7 +643,7 @@ func yaml_emitter_emit_flow_mapping_key(emitter *yaml_emitter_t, event *yaml_eve
if !yaml_emitter_write_indicator(emitter, []byte{'}'}, false, false, false) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -716,7 +716,7 @@ func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_e
return false
}
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -752,7 +752,7 @@ func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_
if !yaml_emitter_emit_node(emitter, event, false, true, false, false) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -828,7 +828,7 @@ func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_
} else if event.sequence_style() != yaml_FLOW_SEQUENCE_STYLE && (event.typ == yaml_MAPPING_START_EVENT || event.typ == yaml_SEQUENCE_START_EVENT) {
// An indented block follows, so write the comment right now.
emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
Expand All @@ -838,7 +838,7 @@ func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_
if !yaml_emitter_emit_node(emitter, event, false, false, true, false) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, false) {
return false
}
if !yaml_emitter_process_foot_comment(emitter) {
Expand Down Expand Up @@ -1144,8 +1144,11 @@ func yaml_emitter_process_head_comment(emitter *yaml_emitter_t) bool {
}

// Write an line comment.
func yaml_emitter_process_line_comment(emitter *yaml_emitter_t) bool {
func yaml_emitter_process_line_comment(emitter *yaml_emitter_t, linebreak bool) bool {
if len(emitter.line_comment) == 0 {
if linebreak && !put_break(emitter) {
return false
}
return true
}
if !emitter.whitespace {
Expand Down Expand Up @@ -1894,7 +1897,7 @@ func yaml_emitter_write_literal_scalar(emitter *yaml_emitter_t, value []byte) bo
if !yaml_emitter_write_block_scalar_hints(emitter, value) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, true) {
return false
}
//emitter.indention = true
Expand Down Expand Up @@ -1931,7 +1934,7 @@ func yaml_emitter_write_folded_scalar(emitter *yaml_emitter_t, value []byte) boo
if !yaml_emitter_write_block_scalar_hints(emitter, value) {
return false
}
if !yaml_emitter_process_line_comment(emitter) {
if !yaml_emitter_process_line_comment(emitter, true) {
return false
}

Expand Down
30 changes: 30 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,36 @@ var nodeTests = []struct {
}},
},
},
{
"a: |2-\n\n\n\n string\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,
Tag: "!!str",
Value: "a",
Line: 1,
Column: 1,
},
{
Kind: yaml.ScalarNode,
Style: yaml.LiteralStyle,
Tag: "!!str",
Value: "\n\n\nstring",
Line: 1,
Column: 4,
},
}},
},
},
},
}

func (s *S) TestNodeRoundtrip(c *C) {
Expand Down