Skip to content

Commit

Permalink
dynamic rules: path-exclude rule fix (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio authored Jul 23, 2024
1 parent 3e99dc9 commit fc8afa4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rules/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (p *parser) parseRuleInfo(st ir.Node, labelStmt ir.Node, proto *Rule) (Rule
rule.Message = proto.Message
rule.Location = proto.Location
rule.Path = proto.Path
rule.PathExcludes = proto.PathExcludes

rule.Filters = make([]map[string]Filter, len(proto.Filters))
for i, filterSet := range proto.Filters {
Expand Down
48 changes: 48 additions & 0 deletions src/tests/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,51 @@ function type_type_check(string $animal_name, int $animal_id) {
}
test.RunRulesTest()
}

func TestRulePathExcludePositive(t *testing.T) {
rfile := `<?php
/**
* @name varEval
* @warning don't eval from variable
* @path www/
* @path-exclude www/no
*/
eval(${"var"});
`
test := linttest.NewSuite(t)
test.RuleFile = rfile
code := `<?php
$hello = 'echo 123;';
eval($hello);
eval('echo 456;');
`
test.AddNamedFile("www/no", code)

test.RunRulesTest()
}

func TestRulePathExcludeNegative(t *testing.T) {
rfile := `<?php
/**
* @name varEval
* @warning don't eval from variable
* @path www/
* @path-exclude www/no
*/
eval(${"var"});
`
test := linttest.NewSuite(t)
test.RuleFile = rfile
code := `<?php
$hello = 'echo 123;';
eval($hello);
eval('echo 456;');
`
test.AddNamedFile("www/no", code)
test.AddNamedFile("www/yes", code)

test.Expect = []string{
`don't eval from variable`,
}
test.RunRulesTest()
}

0 comments on commit fc8afa4

Please sign in to comment.