mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-14 20:03:42 +00:00
fix(deps): bump go-yaml to fix block and folded scalar round-trips (#1321)
Bumps go-yaml to its main branch and drops the workaround it makes obsolete, matching https://github.com/go-gitea/gitea/pull/39787. - go-yaml main keeps block scalar indentation indicators (https://github.com/yaml/go-yaml/pull/414), so values with a leading newline no longer need quoting - `config edit` no longer wraps lines, because go-yaml still wraps more-indented lines of folded scalars and turns a space into a newline Reviewed-on: https://gitea.com/gitea/runner/pulls/1321 Reviewed-by: bircni <[email protected]> Co-authored-by: silverwind <[email protected]>
This commit is contained in:
1 parent
0d84ec6dab
commit
b9aa47d1a5
4 files changed
+11
-25
No files matched your search
@@ -312,29 +312,9 @@ func allScalars(nodes []*yaml.Node) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// quoteLeadingNewlines keeps a scalar starting with a newline out of block style, whose indentation indicator the encoder drops.
|
||||
// TODO: remove once https://github.com/yaml/go-yaml/pull/396 is released.
|
||||
func quoteLeadingNewlines(node *yaml.Node) {
|
||||
if node.Kind == yaml.ScalarNode && strings.HasPrefix(node.Value, "\n") {
|
||||
node.Style = yaml.DoubleQuotedStyle
|
||||
}
|
||||
for _, child := range node.Content {
|
||||
quoteLeadingNewlines(child)
|
||||
}
|
||||
}
|
||||
|
||||
// encodeYAML never wraps lines, go-yaml wraps more-indented lines of folded scalars until https://github.com/yaml/go-yaml/pull/441 is released.
|
||||
func encodeYAML(node *yaml.Node) ([]byte, error) {
|
||||
quoteLeadingNewlines(node)
|
||||
var buf bytes.Buffer
|
||||
encoder := yaml.NewEncoder(&buf)
|
||||
encoder.SetIndent(2)
|
||||
if err := encoder.Encode(node); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := encoder.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
return yaml.Dump(node, yaml.WithV3Defaults(), yaml.WithIndent(2), yaml.WithLineWidth(-1))
|
||||
}
|
||||
|
||||
// restoreLayout re-applies the spacing the encoder drops: the blank lines between
|
||||
|
||||
@@ -280,6 +280,12 @@ func TestEditValuesPreservesFileText(t *testing.T) {
|
||||
edit: func(file string) error { return SetValue(file, "runner.capacity", "4") },
|
||||
added: "runner:\n capacity: 4\n",
|
||||
},
|
||||
{
|
||||
name: "folded scalar with a long more-indented line",
|
||||
content: []byte("runner:\n envs:\n FOLDED: >\n begin\n a more-indented line that is long enough for an encoder wrapping at 80 columns to break\n end\n"),
|
||||
edit: func(file string) error { return SetValue(file, "runner.capacity", "4") },
|
||||
added: " capacity: 4\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
Reference in new issue
Block a user