diff --git a/node_test.go b/node_test.go index b59ed293..9927dad2 100644 --- a/node_test.go +++ b/node_test.go @@ -1559,8 +1559,7 @@ var nodeTests = []struct { Column: 7, }}, }}, - }, - }, + }}, }, }, { // Same as above, but with newline at the end. @@ -1603,8 +1602,7 @@ var nodeTests = []struct { Column: 7, }}, }}, - }, - }, + }}, }, }, { // Same as above, but without FB1. @@ -1646,12 +1644,11 @@ var nodeTests = []struct { Column: 7, }}, }}, - }, - }, + }}, }, }, { - // Same as above, but with two newlines before kb. - "[decode]# HA1\nka:\n # HB1\n\n kb: vb\n# FA1\n", + // Same as above, but with two newlines at the end. Decode-only for that. + "[decode]# HA1\nka:\n # HB1\n kb: vb\n # FB1\n# FA1\n\n", yaml.Node{ Kind: yaml.DocumentNode, Line: 2, @@ -1672,29 +1669,29 @@ var nodeTests = []struct { }, { Kind: yaml.MappingNode, Tag: "!!map", - Line: 5, + Line: 4, Column: 3, Content: []*yaml.Node{{ Kind: yaml.ScalarNode, Tag: "!!str", Value: "kb", - HeadComment: "# HB1\n", - Line: 5, + HeadComment: "# HB1", + FootComment: "# FB1", + Line: 4, Column: 3, }, { Kind: yaml.ScalarNode, Tag: "!!str", Value: "vb", - Line: 5, + Line: 4, Column: 7, }}, }}, - }, - }, + }}, }, }, { - // Same as above, but with two newlines at the end. Decode-only for that. - "[decode]# HA1\nka:\n # HB1\n kb: vb\n # FB1\n# FA1\n\n", + // Similar to above, but make HB1 look more like a footer of ka. + "[decode]# HA1\nka:\n# HB1\n\n kb: vb\n# FA1\n", yaml.Node{ Kind: yaml.DocumentNode, Line: 2, @@ -1715,26 +1712,24 @@ var nodeTests = []struct { }, { Kind: yaml.MappingNode, Tag: "!!map", - Line: 4, + Line: 5, Column: 3, Content: []*yaml.Node{{ Kind: yaml.ScalarNode, Tag: "!!str", Value: "kb", - HeadComment: "# HB1", - FootComment: "# FB1", - Line: 4, + HeadComment: "# HB1\n", + Line: 5, Column: 3, }, { Kind: yaml.ScalarNode, Tag: "!!str", Value: "vb", - Line: 4, + Line: 5, Column: 7, }}, }}, - }, - }, + }}, }, }, { "ka:\n kb: vb\n# FA1\n\nkc: vc\n", diff --git a/scannerc.go b/scannerc.go index 36c7dcdf..40834de7 100644 --- a/scannerc.go +++ b/scannerc.go @@ -2931,7 +2931,7 @@ func yaml_parser_scan_comments(parser *yaml_parser_t, scan_mark yaml_mark_t) boo if close_flow || is_breakz(parser.buffer, parser.buffer_pos+peek) { // Got line break or terminator. if close_flow || !recent_empty { - if close_flow || first_empty && (start_mark.line == foot_line && (parser.flow_level > 0 || start_mark.column-1 == next_indent) || start_mark.column-1 < next_indent) { + if close_flow || first_empty && (start_mark.line == foot_line && token.typ != yaml_VALUE_TOKEN || start_mark.column-1 < next_indent) { // This is the first empty line and there were no empty lines before, // so this initial part of the comment is a foot of the prior token // instead of being a head for the following one. Split it up.