-
Notifications
You must be signed in to change notification settings - Fork 635
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 headless options parsing issue #564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will have issues with paths containing --
for example with args like:
--a=a/b,c/d--z--n--m/a,--c=k,--h
What about changing the parsing function with original type to something like this keeping the previous type goflags.StringSlice
:
func (options *Options) ParseHeadlessOptionalArguments() map[string]string {
var (
lastKey string
optionalArguments = make(map[string]string)
)
for _, v := range options.HeadlessOptionalArguments {
if argParts := strings.SplitN(v, "=", 2); len(argParts) >= 2 {
key := strings.TrimSpace(argParts[0])
value := strings.TrimSpace(argParts[1])
if key != "" && value != "" {
optionalArguments[key] = value
lastKey = key
}
} else if !strings.HasPrefix(v, "--") {
optionalArguments[lastKey] += "," + v
} else {
optionalArguments[v] = ""
}
}
return optionalArguments
}
This reverts commit 5a91a24.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
output of log.Fatalf("%+v", options.Options.ParseHeadlessOptionalArguments())
$ go run main.go -hl -headless -show-browser -ho '--load-extension=extensions/aeehekhncjhhmchjolinnihgdpapmljk,extensions/ogdlpmhglpejoiomcodnpjnfgcpmgale,--disable-gpu,--dummy=qwe,asd' -noi -u https://target
...
2023/08/25 15:16:59 map[--disable-gpu: --dummy:qwe,asd --load-extension:extensions/aeehekhncjhhmchjolinnihgdpapmljk,extensions/ogdlpmhglpejoiomcodnpjnfgcpmgale]
This PR fixes the -
headless-options
parsing issue. Closes #560.go run main.go -hl -headless -show-browser -ho '--load-extension=extensions/aeehekhncjhhmchjolinnihgdpapmljk,extensions/ogdlpmhglpejoiomcodnpjnfgcpmgale,--disable-gpu,--dummy=qwe,asd' -noi -u https://target