mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-23 22:25:42 +00:00
Fixed SEGV error #1096
This commit is contained in:
parent
26356ff4be
commit
bfaafa66f9
@ -24,8 +24,6 @@ func reduceOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
|
|||||||
arrayExpNode := expressionNode.LHS.LHS
|
arrayExpNode := expressionNode.LHS.LHS
|
||||||
array, err := d.GetMatchingNodes(context, arrayExpNode)
|
array, err := d.GetMatchingNodes(context, arrayExpNode)
|
||||||
|
|
||||||
log.Debugf("array of %v things", array.MatchingNodes.Len())
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, err
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ type assignVarPreferences struct {
|
|||||||
func assignVariableOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
func assignVariableOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||||||
lhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.LHS)
|
lhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.LHS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, nil
|
return Context{}, err
|
||||||
}
|
}
|
||||||
if expressionNode.RHS.Operation.OperationType.Type != "GET_VARIABLE" {
|
if expressionNode.RHS.Operation.OperationType.Type != "GET_VARIABLE" {
|
||||||
return Context{}, fmt.Errorf("RHS of 'as' operator must be a variable name e.g. $foo")
|
return Context{}, fmt.Errorf("RHS of 'as' operator must be a variable name e.g. $foo")
|
||||||
|
@ -13,6 +13,12 @@ var variableOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (doc)::{}\n",
|
"D0, P[], (doc)::{}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
document: "a: [cat]",
|
||||||
|
skipDoc: true,
|
||||||
|
expression: "(.[] | {.name: .}) as $item",
|
||||||
|
expectedError: `Cannot index array with 'name' (strconv.ParseInt: parsing "name": invalid syntax)`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Single value variable",
|
description: "Single value variable",
|
||||||
document: `a: cat`,
|
document: `a: cat`,
|
||||||
|
@ -25,6 +25,7 @@ type expressionScenario struct {
|
|||||||
expression string
|
expression string
|
||||||
expected []string
|
expected []string
|
||||||
skipDoc bool
|
skipDoc bool
|
||||||
|
expectedError string
|
||||||
dontFormatInputForDoc bool // dont format input doc for documentation generation
|
dontFormatInputForDoc bool // dont format input doc for documentation generation
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +95,11 @@ func testScenario(t *testing.T, s *expressionScenario) {
|
|||||||
|
|
||||||
context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
|
context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node)
|
||||||
|
|
||||||
|
if s.expectedError != "" {
|
||||||
|
test.AssertResultComplexWithContext(t, s.expectedError, err.Error(), fmt.Sprintf("desc: %v\nexp: %v\ndoc: %v", s.description, s.expression, s.document))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(fmt.Errorf("%w: %v", err, s.expression))
|
t.Error(fmt.Errorf("%w: %v", err, s.expression))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user