mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Fix merge anchor traversing
- Allow inline maps instead of just aliases - Disallow nested sequences - Disallow other types Closes #2386
This commit is contained in:
@@ -25,7 +25,7 @@ foobar:
|
||||
thing: foobar_thing
|
||||
`
|
||||
|
||||
// cannot use merge anchors with arrays
|
||||
// cannot use merge anchors with arrays of non-maps
|
||||
var badAliasSample = `
|
||||
_common: &common-docker-file
|
||||
- FROM ubuntu:18.04
|
||||
@@ -365,6 +365,22 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[0], (!!null)::null\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{<<: {a: 42}}`,
|
||||
expression: `.a`,
|
||||
expected: []string{
|
||||
"D0, P[<< a], (!!int)::42\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{<<: [{a: 42}]}`,
|
||||
expression: `.a`,
|
||||
expected: []string{
|
||||
"D0, P[<< 0 a], (!!int)::42\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: mergeDocSample,
|
||||
@@ -553,9 +569,16 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
skipDoc: true,
|
||||
document: badAliasSample,
|
||||
expression: ".steps[]",
|
||||
expectedError: "can only use merge anchors with maps (!!map), but got !!seq",
|
||||
expectedError: "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing !!str",
|
||||
skipForGoccy: true, // throws an error on parsing, that's fine
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{<<: 42}`,
|
||||
expression: ".[]",
|
||||
expectedError: "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got !!int",
|
||||
skipForGoccy: true,
|
||||
},
|
||||
}
|
||||
|
||||
func TestTraversePathOperatorScenarios(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user