mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 07:08:06 +00:00
Fixed CSV content starting with # issue #2076
This commit is contained in:
parent
7e1722510a
commit
0b7d4b799c
@ -186,6 +186,20 @@ var csvScenarios = []formatScenario{
|
|||||||
expected: expectedYamlFromCSVNoParsing,
|
expected: expectedYamlFromCSVNoParsing,
|
||||||
scenarioType: "decode-csv-no-auto",
|
scenarioType: "decode-csv-no-auto",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "values starting with #, no auto parse",
|
||||||
|
skipDoc: true,
|
||||||
|
input: "value\n#ffff",
|
||||||
|
expected: "- value: '#ffff'\n",
|
||||||
|
scenarioType: "decode-csv-no-auto",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "values starting with #",
|
||||||
|
skipDoc: true,
|
||||||
|
input: "value\n#ffff",
|
||||||
|
expected: "- value: #ffff\n",
|
||||||
|
scenarioType: "decode-csv",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Scalar roundtrip",
|
description: "Scalar roundtrip",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
@ -31,7 +31,7 @@ func (dec *csvObjectDecoder) convertToNode(content string) *CandidateNode {
|
|||||||
node, err := parseSnippet(content)
|
node, err := parseSnippet(content)
|
||||||
// if we're not auto-parsing, then we wont put in parsed objects or arrays
|
// if we're not auto-parsing, then we wont put in parsed objects or arrays
|
||||||
// but we still parse scalars
|
// but we still parse scalars
|
||||||
if err != nil || (!dec.prefs.AutoParse && node.Kind != ScalarNode) {
|
if err != nil || (!dec.prefs.AutoParse && (node.Kind != ScalarNode || node.Value != content)) {
|
||||||
return createScalarNode(content, content)
|
return createScalarNode(content, content)
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
@ -95,10 +95,20 @@ func parseSnippet(value string) (*CandidateNode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.Kind == ScalarNode {
|
||||||
|
result.LineComment = result.LeadingContent
|
||||||
|
} else {
|
||||||
|
result.HeadComment = result.LeadingContent
|
||||||
|
}
|
||||||
|
result.LeadingContent = ""
|
||||||
|
|
||||||
if result.Tag == "!!str" {
|
if result.Tag == "!!str" {
|
||||||
// use the original string value, as
|
// use the original string value, as
|
||||||
// decoding drops new lines
|
// decoding drops new lines
|
||||||
return createScalarNode(value, value), nil
|
newNode := createScalarNode(value, value)
|
||||||
|
newNode.LineComment = result.LineComment
|
||||||
|
return newNode, nil
|
||||||
}
|
}
|
||||||
result.Line = 0
|
result.Line = 0
|
||||||
result.Column = 0
|
result.Column = 0
|
||||||
|
@ -62,6 +62,16 @@ var parseSnippetScenarios = []parseSnippetScenario{
|
|||||||
Column: 0,
|
Column: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
snippet: "# things",
|
||||||
|
expected: &CandidateNode{
|
||||||
|
Kind: ScalarNode,
|
||||||
|
Tag: "!!null",
|
||||||
|
LineComment: "# things",
|
||||||
|
Line: 0,
|
||||||
|
Column: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
snippet: "3.1",
|
snippet: "3.1",
|
||||||
expected: &CandidateNode{
|
expected: &CandidateNode{
|
||||||
|
Loading…
Reference in New Issue
Block a user