Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions url/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package urlutil

import (
"github.com/projectdiscovery/utils/env"
)

// SpaceEncoding determines how spaces are encoded in URLs via external environment variable:
// - When empty (""), spaces are encoded as "+"
// - When set to "percent", spaces are encoded as "%20"
var SpaceEncoding = env.GetEnvOrDefault("SPACE_ENCODING", "")
12 changes: 9 additions & 3 deletions url/rawparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,15 @@ func URLEncodeWithEscapes(data string, charset ...rune) string {
buff.WriteRune('%')
buff.WriteString(getasciihex(r)) // 2 digit hex
case r == ' ':
// prefer using + when space
buff.WriteRune('+')
// case
// use configuration to determine space encoding
switch SpaceEncoding {
case "percent":
buff.WriteRune('%')
buff.WriteRune('2')
buff.WriteRune('0')
default:
buff.WriteRune('+')
}
case r < rune(127):
if _, ok := mustescape[r]; ok {
// reserved char must escape
Expand Down
Loading