Skip to content

Commit

Permalink
Fixed CSV line break issue #1974
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Mar 11, 2024
1 parent 29056ee commit 9e9cb65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/yqlib/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 5 additions & 0 deletions pkg/yqlib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e9cb65

Please sign in to comment.