git-grep: fix for initial dashes in expressions

There is no reason to reject initial dashes in git-grep
expressions... other than the code not supporting it previously.
A new method is introduced to relax the security checks.
This commit is contained in:
Radosław Piliszek 2024-08-12 14:05:01 +02:00
parent 0d2efa2c4a
commit f4d86b4ab0
4 changed files with 45 additions and 1 deletions

View file

@ -61,3 +61,10 @@ func TestCommandString(t *testing.T) {
cmd = NewCommandContextNoGlobals(context.Background(), "url: https://a:b@c/")
assert.EqualValues(t, cmd.prog+` "url: https://sanitized-credential@c/"`, cmd.toString(true))
}
func TestGrepOnlyFunction(t *testing.T) {
cmd := NewCommand(context.Background(), "anything-but-grep")
assert.Panics(t, func() {
cmd.AddGitGrepExpression("whatever")
})
}