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

@ -153,6 +153,18 @@ func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command
return c
}
// AddGitGrepExpression adds an expression option (-e) to git-grep command
// It is different from AddOptionValues in that it allows the actual expression
// to not be filtered out for leading dashes (which is otherwise a security feature
// of AddOptionValues).
func (c *Command) AddGitGrepExpression(exp string) *Command {
if c.args[len(globalCommandArgs)] != "grep" {
panic("function called on a non-grep git program: " + c.args[0])
}
c.args = append(c.args, "-e", exp)
return c
}
// AddOptionFormat adds a new option with a format string and arguments
// For example: AddOptionFormat("--opt=%s %s", val1, val2) means 1 argument: {"--opt=val1 val2"}.
func (c *Command) AddOptionFormat(opt string, args ...any) *Command {