From 563a48d76a243e57c95f5997cc91666e03021c7f Mon Sep 17 00:00:00 2001 From: elsapet Date: Mon, 12 Aug 2024 12:28:32 +0200 Subject: [PATCH] fix: extract variable check to pattern base --- .../detectors/customrule/patternquery/builder/builder.go | 2 +- pkg/scanner/language/pattern.go | 3 +++ pkg/scanner/language/patternbase.go | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/scanner/detectors/customrule/patternquery/builder/builder.go b/pkg/scanner/detectors/customrule/patternquery/builder/builder.go index 54dd96766..1fee7767f 100644 --- a/pkg/scanner/detectors/customrule/patternquery/builder/builder.go +++ b/pkg/scanner/detectors/customrule/patternquery/builder/builder.go @@ -391,7 +391,7 @@ func getVariableFor( } for i, variable := range variables { - if node.Content() == variable.DummyValue { + if patternLanguage.IsVariable(node, variable.DummyValue) { return &variables[i] } } diff --git a/pkg/scanner/language/pattern.go b/pkg/scanner/language/pattern.go index 78d84557b..ffe536e81 100644 --- a/pkg/scanner/language/pattern.go +++ b/pkg/scanner/language/pattern.go @@ -113,4 +113,7 @@ type Pattern interface { // Handle missing errors FixupMissing(node *tree.Node) string + + // Check if node represents variable with given dummy value + IsVariable(node *tree.Node, dummyValue string) bool } diff --git a/pkg/scanner/language/patternbase.go b/pkg/scanner/language/patternbase.go index 2080b7baf..097353b3f 100644 --- a/pkg/scanner/language/patternbase.go +++ b/pkg/scanner/language/patternbase.go @@ -39,3 +39,7 @@ func (*PatternBase) AdjustInput(input string) string { func (*PatternBase) FixupMissing(node *tree.Node) string { return "" } + +func (*PatternBase) IsVariable(node *tree.Node, dummyValue string) bool { + return node.Content() == dummyValue +}