Skip to content

Commit

Permalink
Tune previous change so it fixes go-yaml#686 too.
Browse files Browse the repository at this point in the history
This makes it behave a bit closer to the original PR from Felix as well.
  • Loading branch information
niemeyer committed Jan 6, 2021
1 parent 3778e11 commit c476de3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
41 changes: 18 additions & 23 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,8 +1559,7 @@ var nodeTests = []struct {
Column: 7,
}},
}},
},
},
}},
},
}, {
// Same as above, but with newline at the end.
Expand Down Expand Up @@ -1603,8 +1602,7 @@ var nodeTests = []struct {
Column: 7,
}},
}},
},
},
}},
},
}, {
// Same as above, but without FB1.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scannerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c476de3

Please sign in to comment.