@@ -146,34 +146,107 @@ func (curlCmd *CurlCommand) GetServerDetails() (*config.ServerDetails, error) {
146146// Use this method ONLY after removing all JFrog-CLI flags, i.e. flags in the form: '--my-flag=value' are not allowed.
147147// An argument is any provided candidate which is not a flag or a flag value.
148148func (curlCmd * CurlCommand ) findUriValueAndIndex () (int , string ) {
149- skipThisArg := false
149+ // curlBooleanFlags is a set of curl flags that do NOT take a value.
150+ curlBooleanFlags := map [string ]struct {}{
151+ "-#" : {}, "-:" : {}, "-0" : {}, "-1" : {}, "-2" : {}, "-3" : {}, "-4" : {}, "-6" : {},
152+ "-a" : {}, "-B" : {}, "-f" : {}, "-g" : {}, "-G" : {}, "-I" : {}, "-i" : {},
153+ "-j" : {}, "-J" : {}, "-k" : {}, "-l" : {}, "-L" : {}, "-M" : {}, "-n" : {},
154+ "-N" : {}, "-O" : {}, "-p" : {}, "-q" : {}, "-R" : {}, "-s" : {}, "-S" : {},
155+ "-v" : {}, "-V" : {}, "-Z" : {},
156+ "--anyauth" : {}, "--append" : {}, "--basic" : {}, "--ca-native" : {},
157+ "--cert-status" : {}, "--compressed" : {}, "--compressed-ssh" : {},
158+ "--create-dirs" : {}, "--crlf" : {}, "--digest" : {}, "--disable" : {},
159+ "--disable-eprt" : {}, "--disable-epsv" : {}, "--disallow-username-in-url" : {},
160+ "--doh-cert-status" : {}, "--doh-insecure" : {}, "--fail" : {},
161+ "--fail-early" : {}, "--fail-with-body" : {}, "--false-start" : {},
162+ "--form-escape" : {}, "--ftp-create-dirs" : {}, "--ftp-pasv" : {},
163+ "--ftp-pret" : {}, "--ftp-skip-pasv-ip" : {}, "--ftp-ssl-ccc" : {},
164+ "--ftp-ssl-control" : {}, "--get" : {}, "--globoff" : {},
165+ "--haproxy-protocol" : {}, "--head" : {}, "--http0.9" : {}, "--http1.0" : {},
166+ "--http1.1" : {}, "--http2" : {}, "--http2-prior-knowledge" : {},
167+ "--http3" : {}, "--http3-only" : {}, "--ignore-content-length" : {},
168+ "--include" : {}, "--insecure" : {}, "--ipv4" : {}, "--ipv6" : {},
169+ "--junk-session-cookies" : {}, "--list-only" : {}, "--location" : {},
170+ "--location-trusted" : {}, "--mail-rcpt-allowfails" : {}, "--manual" : {},
171+ "--metalink" : {}, "--negotiate" : {}, "--netrc" : {}, "--netrc-optional" : {},
172+ "--next" : {}, "--no-alpn" : {}, "--no-buffer" : {}, "--no-clobber" : {},
173+ "--no-keepalive" : {}, "--no-npn" : {}, "--no-progress-meter" : {},
174+ "--no-sessionid" : {}, "--ntlm" : {}, "--ntlm-wb" : {}, "--parallel" : {},
175+ "--parallel-immediate" : {}, "--path-as-is" : {}, "--post301" : {},
176+ "--post302" : {}, "--post303" : {}, "--progress-bar" : {},
177+ "--proxy-anyauth" : {}, "--proxy-basic" : {}, "--proxy-ca-native" : {},
178+ "--proxy-digest" : {}, "--proxy-http2" : {}, "--proxy-insecure" : {},
179+ "--proxy-negotiate" : {}, "--proxy-ntlm" : {}, "--proxy-ssl-allow-beast" : {},
180+ "--proxy-ssl-auto-client-cert" : {}, "--proxy-tlsv1" : {}, "--proxytunnel" : {},
181+ "--raw" : {}, "--remote-header-name" : {}, "--remote-name" : {},
182+ "--remote-name-all" : {}, "--remote-time" : {}, "--remove-on-error" : {},
183+ "--retry-all-errors" : {}, "--retry-connrefused" : {}, "--sasl-ir" : {},
184+ "--show-error" : {}, "--silent" : {}, "--socks5-basic" : {},
185+ "--socks5-gssapi" : {}, "--socks5-gssapi-nec" : {}, "--ssl" : {},
186+ "--ssl-allow-beast" : {}, "--ssl-auto-client-cert" : {}, "--ssl-no-revoke" : {},
187+ "--ssl-reqd" : {}, "--ssl-revoke-best-effort" : {}, "--sslv2" : {},
188+ "--sslv3" : {}, "--styled-output" : {}, "--suppress-connect-headers" : {},
189+ "--tcp-fastopen" : {}, "--tcp-nodelay" : {}, "--tftp-no-options" : {},
190+ "--tlsv1" : {}, "--tlsv1.0" : {}, "--tlsv1.1" : {}, "--tlsv1.2" : {},
191+ "--tlsv1.3" : {}, "--tr-encoding" : {}, "--trace-ids" : {},
192+ "--trace-time" : {}, "--use-ascii" : {}, "--verbose" : {}, "--version" : {},
193+ "--xattr" : {},
194+ }
195+
196+ // isBooleanFlag checks if a flag is in the boolean flags
197+ isBooleanFlag := func (flag string ) bool {
198+ _ , exists := curlBooleanFlags [flag ]
199+ return exists
200+ }
201+
202+ skipNextArg := false
150203 for index , arg := range curlCmd .arguments {
151- // Check if shouldn't check current arg.
152- if skipThisArg {
153- skipThisArg = false
204+ // Check if this arg should be skipped (it's a value for the previous flag)
205+ if skipNextArg {
206+ skipNextArg = false
154207 continue
155208 }
156- // If starts with '--', meaning a flag which its value is at next slot.
157- if strings .HasPrefix (arg , "--" ) {
158- skipThisArg = true
159- continue
160- }
161- // Check if '-'.
209+
210+ // Check if this is a flag
162211 if strings .HasPrefix (arg , "-" ) {
163- if len ( arg ) > 2 {
164- // Meaning that this flag also contains its value.
212+ // Check for flags with inline values like --header=value
213+ if strings . HasPrefix ( arg , "--" ) && strings . Contains ( arg , "=" ) {
165214 continue
166215 }
167- // If reached here, means that the flag value is at the next arg.
168- skipThisArg = true
216+
217+ // Check if it a boolean flag
218+ if isBooleanFlag (arg ) {
219+ continue
220+ }
221+
222+ // For short flags
223+ if ! strings .HasPrefix (arg , "--" ) && len (arg ) > 2 {
224+ // find a flag that takes a value, everything after it is the inline value
225+ for i := 1 ; i < len (arg ); i ++ {
226+ charFlag := "-" + string (arg [i ])
227+ if ! isBooleanFlag (charFlag ) {
228+ // Found a flag that takes a value
229+ if i < len (arg )- 1 {
230+ // Inline value exists (e.g., -XGET, -Lotest.txt)
231+ break
232+ }
233+ // No inline value (e.g., -Lo, -sX), next arg is the value
234+ skipNextArg = true
235+ break
236+ }
237+ }
238+ continue
239+ }
240+
241+ // Flag takes a value in the next argument
242+ skipNextArg = true
169243 continue
170244 }
171245
172- // Found an argument
246+ // Found a non-flag argument - this is the URL/API path
173247 return index , arg
174248 }
175249
176- // If reached here, didn't find an argument.
177250 return - 1 , ""
178251}
179252
0 commit comments