Skip to content

Commit

Permalink
make equals optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Dec 4, 2023
1 parent 0470166 commit 16d3dc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions url/orderedparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
// OrderedParams is a map that preserves the order of elements
type OrderedParams struct {
om mapsutil.OrderedMap[string, []string]
// IncludeEquals is used to include = in encoded parameters, default is false
IncludeEquals bool
}

// NewOrderedParams creates a new ordered params
Expand Down Expand Up @@ -103,8 +105,8 @@ func (o *OrderedParams) Encode() string {
}
buf.WriteString(keyEscaped)
value := ParamEncode(v)
// donot specify = if parameter has no value (reference: nuclei-templates)
if value != "" {
//donot specify = if parameter has no value (reference: nuclei-templates)
if o.IncludeEquals || value != "" {
buf.WriteRune('=')
buf.WriteString(value)
}
Expand Down
14 changes: 14 additions & 0 deletions url/orderedparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ func TestGetOrderedParams(t *testing.T) {
require.Equalf(t, p.Get("sqli"), values.Get("sqli"), "malformed or missing value for param sqli expected %v but got %v", values.Get("sqli"), p.Get("sqli"))
require.Equalf(t, p.Get("xss"), values.Get("xss"), "malformed or missing value for param xss expected %v but got %v", values.Get("xss"), p.Get("xss"))
}

func TestIncludeEquals(t *testing.T) {
p := NewOrderedParams()
p.Add("key1", "")
p.Add("key2", "value2")
if encoded := p.Encode(); encoded != "key1&key2=value2" {
t.Errorf("Expected 'key1&key2=value2', got '%s'", encoded)
}

p.IncludeEquals = true
if encoded := p.Encode(); encoded != "key1=&key2=value2" {
t.Errorf("Expected 'key1=&key2=value2', got '%s'", encoded)
}
}

0 comments on commit 16d3dc7

Please sign in to comment.