Skip to content

Commit

Permalink
Fix maskInlineIgnore to handle non-ascii input
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed May 7, 2024
1 parent 5d52c15 commit a30844d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 1 addition & 9 deletions pkg/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,7 @@ func maskInlineIgnore(line string) string {
return line
}

lineWithoutIgnoreRule := []rune(line)

start := inlineIgnoreMatch[0]
end := inlineIgnoreMatch[1]

for i := start; i < end; i++ {
// use null terminator to indicate a masked character
lineWithoutIgnoreRule[i] = rune(0)
}
lineWithoutIgnoreRule := ignoreRuleRegex.ReplaceAll([]byte(line), []byte{})

return string(lineWithoutIgnoreRule)
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,23 @@ func Test_maskInlineIgnore(t *testing.T) {
{
desc: "replace wokeignore:rule",
line: "wokeignore:rule=master-slave",
expected: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
expected: "",
},
{
desc: "not replace wokeignore:rule",
line: "no inline ignore",
expected: "no inline ignore",
},
{
desc: "text alongside wokeignore:rule is preserved",
line: "abc wokeignore:rule=master-slave",
expected: "abc ",
},
{
desc: "Non-ascii characters are handled correctly",
line: "Include’s non-ascii wokeignore:rule=master",
expected: "Include’s non-ascii ",
},
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
Expand Down

0 comments on commit a30844d

Please sign in to comment.