EncodeQuery is a copy-paste of url.Values.Encode, except it uses %20 instead of + to encode spaces. This is necessary to correctly render spaces in some authenticator apps, like Google Authenticator.
(v url.Values)
| 10 | // of + to encode spaces. This is necessary to correctly render spaces in some |
| 11 | // authenticator apps, like Google Authenticator. |
| 12 | func EncodeQuery(v url.Values) string { |
| 13 | if v == nil { |
| 14 | return "" |
| 15 | } |
| 16 | var buf strings.Builder |
| 17 | keys := make([]string, 0, len(v)) |
| 18 | for k := range v { |
| 19 | keys = append(keys, k) |
| 20 | } |
| 21 | sort.Strings(keys) |
| 22 | for _, k := range keys { |
| 23 | vs := v[k] |
| 24 | keyEscaped := url.PathEscape(k) // changed from url.QueryEscape |
| 25 | for _, v := range vs { |
| 26 | if buf.Len() > 0 { |
| 27 | buf.WriteByte('&') |
| 28 | } |
| 29 | buf.WriteString(keyEscaped) |
| 30 | buf.WriteByte('=') |
| 31 | buf.WriteString(url.PathEscape(v)) // changed from url.QueryEscape |
| 32 | } |
| 33 | } |
| 34 | return buf.String() |
| 35 | } |