diff --git a/url/encoding.go b/url/encoding.go new file mode 100644 index 0000000..48023d7 --- /dev/null +++ b/url/encoding.go @@ -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", "") diff --git a/url/rawparam.go b/url/rawparam.go index 741715e..9007daf 100644 --- a/url/rawparam.go +++ b/url/rawparam.go @@ -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