Skip to content

Commit

Permalink
Fix headless options parsing issue (#564)
Browse files Browse the repository at this point in the history
* fix headless options

* Revert "fix headless options"

This reverts commit 5a91a24.

* use StringSliceVarP

* disabling default logger

---------

Co-authored-by: Mzack9999 <[email protected]>
  • Loading branch information
dogancanbakir and Mzack9999 authored Aug 25, 2023
1 parent 05a22f2 commit 9f73fe8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/projectdiscovery/katana/pkg/utils"
errorutil "github.com/projectdiscovery/utils/errors"
fileutil "github.com/projectdiscovery/utils/file"
logutil "github.com/projectdiscovery/utils/log"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -112,7 +113,7 @@ func configureOutput(options *types.Options) {
gologger.DefaultLogger.SetMaxLevel(levels.LevelInfo)
}

// logutil.DisableDefaultLogger()
logutil.DisableDefaultLogger()
}

func initExampleFormFillConfig() error {
Expand Down
13 changes: 12 additions & 1 deletion pkg/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,25 @@ func (options *Options) ParseCustomHeaders() map[string]string {
}

func (options *Options) ParseHeadlessOptionalArguments() map[string]string {
optionalArguments := make(map[string]string)
var (
lastKey string
optionalArguments = make(map[string]string)
)
for _, v := range options.HeadlessOptionalArguments {
if v == "" {
continue
}
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
Expand Down
15 changes: 15 additions & 0 deletions pkg/types/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ func TestParseHeadlessOptionalArguments(t *testing.T) {
input: "a=b,a=b",
want: map[string]string{"a": "b"},
},
{
name: "values with dash with boolean flag at the end",
input: "--a=a/b,c/d--z--n--m/a,--c=k,--h",
want: map[string]string{"--a": "a/b,c/d--z--n--m/a", "--c": "k", "--h": ""},
},
{
name: "values with dash boolean flag at the beginning",
input: "--h,--a=a/b,c/d--z--n--m/a,--c=k",
want: map[string]string{"--h": "", "--a": "a/b,c/d--z--n--m/a", "--c": "k"},
},
{
name: "values with dash boolean flag in the middle",
input: "--a=a/b,c/d--z--n--m/a,--h,--c=k",
want: map[string]string{"--a": "a/b,c/d--z--n--m/a", "--h": "", "--c": "k"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9f73fe8

Please sign in to comment.