Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix maskInlineIgnore to handle non-ascii input #279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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