Skip to content

Commit

Permalink
fix random string bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi committed Oct 19, 2024
1 parent 989b296 commit d9ff490
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions worker/pkg/benthos/transformers/generate_random_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ func NewGenerateRandomStringOptsFromConfig(config *mgmtv1alpha1.GenerateString,
nil,
)
}
minValue := config.GetMin()
maxValue := config.GetMax()
if maxLen != nil {
minValue = transformer_utils.MinInt(minValue, *maxLen) // ensure the min is not larger than the max allowed length
maxValue = transformer_utils.Ceil(maxValue, *maxLen)
minValue := config.Min
maxValue := config.Max
if maxLen != nil && maxValue != nil {
newMax := transformer_utils.Ceil(*maxValue, *maxLen)
maxValue = &newMax
}
if minValue != nil {
newMin := transformer_utils.MinInt(*minValue, *maxValue) // ensure the min is not larger than the max allowed length
minValue = &newMin
}

return NewGenerateRandomStringOpts(
&minValue,
&maxValue,
minValue,
maxValue,
nil,
)
}
Expand Down

0 comments on commit d9ff490

Please sign in to comment.