@@ -100,15 +100,18 @@ func (c *Command) SetDescription(desc string) *Command {
100
100
return c
101
101
}
102
102
103
- func isSafeDynArg (s string ) bool {
103
+ // isSafeArgumentValue checks if the argument is safe to be used as a value (not an option)
104
+ func isSafeArgumentValue (s string ) bool {
104
105
return s == "" || s [0 ] != '-'
105
106
}
106
107
107
- func isValidOption (s string ) bool {
108
+ // isValidArgumentOption checks if the argument is a valid option (starting with '-').
109
+ // It doesn't check whether the option is supported or not
110
+ func isValidArgumentOption (s string ) bool {
108
111
return s != "" && s [0 ] == '-'
109
112
}
110
113
111
- // AddArguments adds new git arguments to the command. It only accepts string literals, or trusted CmdArg.
114
+ // AddArguments adds new git arguments (option/value) to the command. It only accepts string literals, or trusted CmdArg.
112
115
// Type CmdArg is in the internal package, so it can not be used outside of this package directly,
113
116
// it makes sure that user-provided arguments won't cause RCE risks.
114
117
// User-provided arguments should be passed by other AddXxx functions
@@ -121,9 +124,9 @@ func (c *Command) AddArguments(args ...internal.CmdArg) *Command {
121
124
122
125
// AddOptionValues adds a new option with a list of non-option values
123
126
// For example: AddOptionValues("--opt", val) means 2 arguments: {"--opt", val}.
124
- // The values are treated as dynamic arguments . It equals to: AddArguments("--opt") then AddDynamicArguments(val).
127
+ // The values are treated as dynamic argument values . It equals to: AddArguments("--opt") then AddDynamicArguments(val).
125
128
func (c * Command ) AddOptionValues (opt internal.CmdArg , args ... string ) * Command {
126
- if ! isValidOption (string (opt )) {
129
+ if ! isValidArgumentOption (string (opt )) {
127
130
c .brokenArgs = append (c .brokenArgs , string (opt ))
128
131
return c
129
132
}
@@ -135,7 +138,7 @@ func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command
135
138
// AddOptionFormat adds a new option with a format string and arguments
136
139
// For example: AddOptionFormat("--opt=%s %s", val1, val2) means 1 argument: {"--opt=val1 val2"}.
137
140
func (c * Command ) AddOptionFormat (opt string , args ... any ) * Command {
138
- if ! isValidOption (opt ) {
141
+ if ! isValidArgumentOption (opt ) {
139
142
c .brokenArgs = append (c .brokenArgs , opt )
140
143
return c
141
144
}
@@ -145,11 +148,12 @@ func (c *Command) AddOptionFormat(opt string, args ...any) *Command {
145
148
return c
146
149
}
147
150
148
- // AddDynamicArguments adds new dynamic arguments to the command.
151
+ // AddDynamicArguments adds new dynamic argument values to the command.
149
152
// The arguments may come from user input and can not be trusted, so no leading '-' is allowed to avoid passing options.
153
+ // TODO: in the future, this function can be renamed to AddArgumentValues
150
154
func (c * Command ) AddDynamicArguments (args ... string ) * Command {
151
155
for _ , arg := range args {
152
- if ! isSafeDynArg (arg ) {
156
+ if ! isSafeArgumentValue (arg ) {
153
157
c .brokenArgs = append (c .brokenArgs , arg )
154
158
}
155
159
}
0 commit comments