Skip to content
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

Merged
merged 4 commits into from
Aug 25, 2023
Merged

Fix headless options parsing issue #564

merged 4 commits into from
Aug 25, 2023

Conversation

dogancanbakir
Copy link
Member

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
image

@dogancanbakir dogancanbakir self-assigned this Aug 19, 2023
@dogancanbakir dogancanbakir changed the base branch from main to dev August 19, 2023 14:15
Copy link
Member

@Mzack9999 Mzack9999 left a 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
}

Copy link
Member

@Mzack9999 Mzack9999 left a 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]

@Mzack9999 Mzack9999 added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Aug 25, 2023
@ehsandeep ehsandeep merged commit 9f73fe8 into dev Aug 25, 2023
13 checks passed
@ehsandeep ehsandeep deleted the fix_headless_options branch August 25, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Headless Options not supporting multiple extensions
3 participants