diff --git a/url/orderedparams.go b/url/orderedparams.go index e7b78b2..6367a7d 100644 --- a/url/orderedparams.go +++ b/url/orderedparams.go @@ -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 @@ -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) } diff --git a/url/orderedparams_test.go b/url/orderedparams_test.go index 70d10f9..4a7343a 100644 --- a/url/orderedparams_test.go +++ b/url/orderedparams_test.go @@ -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) + } +}