Skip to content

Commit

Permalink
refactor(fuzz): use mapsutil.Map type
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <git@dw1.io>
  • Loading branch information
dwisiswant0 committed Aug 23, 2024
1 parent 56af26a commit 9165773
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions pkg/fuzz/component/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/projectdiscovery/nuclei/v3/pkg/fuzz/dataformat"
"github.com/projectdiscovery/retryablehttp-go"
"github.com/projectdiscovery/utils/maps"
urlutil "github.com/projectdiscovery/utils/url"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ func (q *Path) Delete(key string) error {
// Rebuild returns a new request with the
// component rebuilt
func (q *Path) Rebuild() (*retryablehttp.Request, error) {
originalValues := make(map[string]interface{})
originalValues := mapsutil.Map[string, any]{}
splitted := strings.Split(q.req.URL.Path, "/")
for i := range splitted {
pathTillNow := strings.Join(splitted[:i+1], "/")
Expand All @@ -95,8 +96,14 @@ func (q *Path) Rebuild() (*retryablehttp.Request, error) {
lengthSplitted := len(q.value.parsed.Map)
for i := lengthSplitted; i > 0; i-- {
key := strconv.Itoa(i)
original := originalValues[key].(string)
new := q.value.parsed.Map[key].(string)

original := originalValues.GetOrDefault(key, "").(string)
new := q.value.parsed.Map.GetOrDefault(key, "").(string)
if new == original {
// no need to replace
continue
}

originalPath = strings.Replace(originalPath, original, new, 1)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/fuzz/component/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (v *Value) SetParsedValue(key string, value string) bool {
v.parsed.Set(key, value)
return true
}

// TODO(dwisiswant0): I'm sure that this can be simplified because
// `dataformat.KV.*` is a type of `mapsutil.*` where the value is `any`. So,
// it looks like we won't type conversion here or even have its own methods
// inside `dataformat.KV`.

// If the value is a list, append to it
// otherwise replace it
switch v := origValue.(type) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fuzz/dataformat/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// if it's not important/significant (ex: json,xml) we use map
// this also allows us to iteratively implement ordered map
type KV struct {
Map map[string]interface{}
Map mapsutil.Map[string, any]
OrderedMap *mapsutil.OrderedMap[string, any]
}

Expand Down

0 comments on commit 9165773

Please sign in to comment.