From 9e9cb65ec0063c144bd72443bf48351518be17c1 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 12 Mar 2024 10:22:35 +1100 Subject: [PATCH] Fixed CSV line break issue #1974 --- pkg/yqlib/csv_test.go | 7 +++++++ pkg/yqlib/lib.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/pkg/yqlib/csv_test.go b/pkg/yqlib/csv_test.go index a1cbb423..b56f9aea 100644 --- a/pkg/yqlib/csv_test.go +++ b/pkg/yqlib/csv_test.go @@ -172,6 +172,13 @@ var csvScenarios = []formatScenario{ expected: expectedYamlFromCSVWithObject, scenarioType: "decode-csv", }, + { + description: "Decode CSV line breaks", + skipDoc: true, + input: "heading1\n\"some data\nwith a line break\"\n", + expected: "- heading1: |-\n some data\n with a line break\n", + scenarioType: "decode-csv", + }, { description: "Parse CSV into an array of objects, no auto-parsing", subdescription: "First row is assumed to be the header row. Entries with YAML/JSON will be left as strings.", diff --git a/pkg/yqlib/lib.go b/pkg/yqlib/lib.go index c917c254..ad4aa38f 100644 --- a/pkg/yqlib/lib.go +++ b/pkg/yqlib/lib.go @@ -95,6 +95,11 @@ func parseSnippet(value string) (*CandidateNode, error) { if err != nil { return nil, err } + if result.Tag == "!!str" { + // use the original string value, as + // decoding drops new lines + return createScalarNode(value, value), nil + } result.Line = 0 result.Column = 0 return result, err