mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +00:00
Fixed multiply string by negative number panic #2211
This commit is contained in:
parent
5273715428
commit
2201381235
@ -153,6 +153,8 @@ func repeatString(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error
|
|||||||
count, err := parseInt(intNode.Value)
|
count, err := parseInt(intNode.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if count < 0 {
|
||||||
|
return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count)
|
||||||
}
|
}
|
||||||
target.Value = strings.Repeat(stringNode.Value, count)
|
target.Value = strings.Repeat(stringNode.Value, count)
|
||||||
|
|
||||||
|
@ -201,6 +201,13 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
fmt.Sprintf("D0, P[], (!!str)::%s\n", strings.Repeat("banana", 4)),
|
fmt.Sprintf("D0, P[], (!!str)::%s\n", strings.Repeat("banana", 4)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Multiply string X by negative int",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `n: -4`,
|
||||||
|
expression: `"banana" * .n`,
|
||||||
|
expectedError: "Cannot repeat string by a negative number (-4)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Multiply int node X string",
|
description: "Multiply int node X string",
|
||||||
document: `n: 4
|
document: `n: 4
|
||||||
|
Loading…
Reference in New Issue
Block a user