Skip to content

Commit

Permalink
bug: Add back case insensitivity to rule regex (#110)
Browse files Browse the repository at this point in the history
* Add case sensitive test

* Add back case insensitive to regex
  • Loading branch information
caitlinelfring authored Jul 21, 2021
1 parent 5b45f81 commit 4c46b2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions pkg/rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -125,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 {
Expand Down

0 comments on commit 4c46b2f

Please sign in to comment.