From a90b0a121e8b3750749581b74fad9d7392d3d9a6 Mon Sep 17 00:00:00 2001 From: Caitlin Elfring Date: Wed, 21 Jul 2021 18:55:36 -0400 Subject: [PATCH 1/2] Add case sensitive test --- pkg/rule/rule_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/rule/rule_test.go b/pkg/rule/rule_test.go index 39910651..2eac1b79 100644 --- a/pkg/rule/rule_test.go +++ b/pkg/rule/rule_test.go @@ -31,6 +31,7 @@ func TestRule_FindMatchIndexes(t *testing.T) { {"this string has rule-2 and rule1 included", [][]int{{27, 32}}, [][]int{{27, 32}}}, {"this string does not have any findings", [][]int(nil), [][]int(nil)}, {"this string has finding with word boundary rule1rule-1", [][]int{{43, 48}, {48, 54}}, [][]int(nil)}, + {"this string has finding with word boundary Rule1rule-1", [][]int{{43, 48}, {48, 54}}, [][]int(nil)}, } for _, test := range tests { r := testRule() From 0f9a2357851cb64484bc5ddd63562e631f570649 Mon Sep 17 00:00:00 2001 From: Caitlin Elfring Date: Wed, 21 Jul 2021 18:55:58 -0400 Subject: [PATCH 2/2] Add back case insensitive to regex --- pkg/rule/rule.go | 1 + pkg/rule/rule_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/rule/rule.go b/pkg/rule/rule.go index ec4f1914..0231a272 100644 --- a/pkg/rule/rule.go +++ b/pkg/rule/rule.go @@ -89,6 +89,7 @@ func (r *Rule) setRegex() { func (r *Rule) regexString() string { regex := func(start, end string) string { s := strings.Builder{} + s.WriteString("(?i)") s.WriteString(start) s.WriteString("(%s)") s.WriteString(end) diff --git a/pkg/rule/rule_test.go b/pkg/rule/rule_test.go index 2eac1b79..ad7bce88 100644 --- a/pkg/rule/rule_test.go +++ b/pkg/rule/rule_test.go @@ -126,33 +126,33 @@ func TestRule_regexString(t *testing.T) { { desc: "default", rule: testRule(), - expected: `(%s)`, + expected: `(?i)(%s)`, }, { desc: "word boundary", rule: testRuleWithOptions(Options{WordBoundary: true}), - expected: `\b(%s)\b`, + expected: `(?i)\b(%s)\b`, }, { desc: "word boundary start", rule: testRuleWithOptions(Options{WordBoundaryStart: true}), - expected: `\b(%s)`, + expected: `(?i)\b(%s)`, }, { desc: "word boundary end", rule: testRuleWithOptions(Options{WordBoundaryEnd: true}), - expected: `(%s)\b`, + expected: `(?i)(%s)\b`, }, { desc: "word boundary start and end", rule: testRuleWithOptions(Options{WordBoundaryStart: true, WordBoundaryEnd: true}), - expected: `\b(%s)\b`, + expected: `(?i)\b(%s)\b`, }, { // To show that enabling WordBoundary will win over other options desc: "word boundary and word boundary start/end false", rule: testRuleWithOptions(Options{WordBoundary: true, WordBoundaryStart: false, WordBoundaryEnd: false}), - expected: `\b(%s)\b`, + expected: `(?i)\b(%s)\b`, }, } for _, tt := range tests {