mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed bug in splice operator #1511
This commit is contained in:
parent
d7da0cca3c
commit
3b84c03131
@ -48,6 +48,8 @@ func sliceArrayOperator(d *dataTreeNavigator, context Context, expressionNode *E
|
|||||||
relativeSecondNumber := secondNumber
|
relativeSecondNumber := secondNumber
|
||||||
if relativeSecondNumber < 0 {
|
if relativeSecondNumber < 0 {
|
||||||
relativeSecondNumber = len(original.Content) + secondNumber
|
relativeSecondNumber = len(original.Content) + secondNumber
|
||||||
|
} else if relativeSecondNumber > len(original.Content) {
|
||||||
|
relativeSecondNumber = len(original.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("calculateIndicesToTraverse: slice from %v to %v", relativeFirstNumber, relativeSecondNumber)
|
log.Debug("calculateIndicesToTraverse: slice from %v to %v", relativeFirstNumber, relativeSecondNumber)
|
||||||
|
@ -55,6 +55,24 @@ var sliceArrayScenarios = []expressionScenario{
|
|||||||
"D0, P[1], (!!seq)::- banana\n- grape\n",
|
"D0, P[1], (!!seq)::- banana\n- grape\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "second index beyond array clamps",
|
||||||
|
document: `[cat]`,
|
||||||
|
expression: `.[:3]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::- cat\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "first index beyond array returns nothing",
|
||||||
|
document: `[cat]`,
|
||||||
|
expression: `.[3:]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
document: `[[cat, dog, frog, cow], [apple, banana, grape, mango]]`,
|
document: `[[cat, dog, frog, cow], [apple, banana, grape, mango]]`,
|
||||||
|
Loading…
Reference in New Issue
Block a user