Skip to content

Commit

Permalink
Fix panic with substr interpolation function by invalid offset
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Jan 5, 2018
1 parent 18975d7 commit e873af9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/interpolate_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ func interpolationFuncSubstr() ast.Function {
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")
}

Expand Down
5 changes: 5 additions & 0 deletions config/interpolate_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,11 @@ func TestInterpolateFuncSubstr(t *testing.T) {
nil,
true,
},
{
`${substr("foo", -4, -1)}`,
nil,
true,
},

// invalid length
{
Expand Down

0 comments on commit e873af9

Please sign in to comment.