mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Fix panic with substr interpolation function by invalid offset
Fixes #17041
This commit is contained in:
committed by
Masayuki Morita
parent
18975d7270
commit
e873af9337
@@ -1577,7 +1577,7 @@ func interpolationFuncSubstr() ast.Function {
|
|||||||
return nil, fmt.Errorf("length should be a non-negative integer")
|
return nil, fmt.Errorf("length should be a non-negative integer")
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset > len(str) {
|
if offset > len(str) || offset < 0 {
|
||||||
return nil, fmt.Errorf("offset cannot be larger than the length of the string")
|
return nil, fmt.Errorf("offset cannot be larger than the length of the string")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2568,6 +2568,11 @@ func TestInterpolateFuncSubstr(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`${substr("foo", -4, -1)}`,
|
||||||
|
nil,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
// invalid length
|
// invalid length
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user