diff --git a/go.mod b/go.mod index 896d8832..ffd5ec92 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( go.opentelemetry.io/otel/sdk v1.47.0 go.opentelemetry.io/otel/trace v1.47.0 go.opentelemetry.io/proto/otlp v1.11.1 - go.yaml.in/yaml/v4 v4.0.0-rc.6 + go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525 golang.org/x/net v0.60.0 golang.org/x/sync v0.24.0 golang.org/x/sys v0.49.0 diff --git a/go.sum b/go.sum index a0841295..bb31c341 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,8 @@ go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= -go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4= -go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525 h1:FtzHH3s777Nx50YcPAcodAPm1mNakc228nMYbr3f+90= +go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU= golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= diff --git a/internal/pkg/config/edit.go b/internal/pkg/config/edit.go index 0b38ccf1..f65b6d32 100644 --- a/internal/pkg/config/edit.go +++ b/internal/pkg/config/edit.go @@ -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 diff --git a/internal/pkg/config/edit_test.go b/internal/pkg/config/edit_test.go index e1284884..c7366010 100644 --- a/internal/pkg/config/edit_test.go +++ b/internal/pkg/config/edit_test.go @@ -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 {