Skip to content

Commit 4910e44

Browse files
committed
Change encoding for SP character
According to RFC 1866 and RFC 3986, the `SP` character can only be encoded as `+` in application/x-www-form-urlencoded values. But encoding it as `%20` is always correct. Therefore, prefer to encode with `%20`.
1 parent a8cef66 commit 4910e44

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

url/rawparam.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ func URLEncodeWithEscapes(data string, charset ...rune) string {
175175
buff.WriteRune('%')
176176
buff.WriteString(getasciihex(r)) // 2 digit hex
177177
case r == ' ':
178-
// prefer using + when space
179-
buff.WriteRune('+')
178+
// prefer using %20 when space (RFC 1866, RFC 3986)
179+
buff.WriteRune('%')
180+
buff.WriteRune('2')
181+
buff.WriteRune('0')
180182
// case
181183
case r < rune(127):
182184
if _, ok := mustescape[r]; ok {

0 commit comments

Comments
 (0)