Skip to content

Commit

Permalink
Fix setvar to take the value as ---test
Browse files Browse the repository at this point in the history
  • Loading branch information
soujanyanmbri committed Aug 5, 2024
1 parent 010509a commit 278fd77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/actions/setvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ func (a *setvarFn) evaluateTxCollection(r plugintypes.RuleMetadata, tx plugintyp
if len(value) > 1 {
val, err = strconv.Atoi(value[1:])
if err != nil {
tx.DebugLogger().Error().
Str("var_value", value).
Int("rule_id", r.ID()).
Err(err).
Msg("Invalid value")
// If the variable doesn't exist, we would need to raise an error. Otherwise, it should be the same value.
if strings.HasPrefix(value[1:], "tx.") {
tx.DebugLogger().Error().
Str("var_value", value).
Int("rule_id", r.ID()).
Err(err).
Msg(value)
return
}

col.Set(key, []string{value})
return
}
}
Expand Down
10 changes: 10 additions & 0 deletions internal/actions/setvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ func TestSetvarEvaluate(t *testing.T) {
init: "TX.newvar=-%{tx.missingvar}",
expectInvalidSyntaxError: true,
},
{
name: "Non Numerical Operation - If the value starts with -",
init: "TX.newvar=----expected_value",
expectInvalidSyntaxError: false,
},
{
name: "Non Numerical Operation - If the value starts with +",
init: "TX.newvar=+++expected_value",
expectInvalidSyntaxError: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 278fd77

Please sign in to comment.