[PATCH 2/3] Make buf_append_urlencoded() percent-encode fewer characters.

Daniel Lenski dlenski at gmail.com
Fri Oct 14 18:46:33 PDT 2016


Per RFC 3986, the characters '-', '_', '.', '~' don't need to be
percent-encoded anywhere in a URL or query string.  And ' ' can simply be
replaced with '+' rather than "%20".

Signed-off-by: Daniel Lenski <dlenski at gmail.com>
---
 http.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/http.c b/http.c
index 1b99319..c115632 100644
--- a/http.c
+++ b/http.c
@@ -45,8 +45,10 @@ void buf_append_urlencoded(struct oc_text_buf *buf, const char *str)
 {
 	while (str && *str) {
 		unsigned char c = *str;
-		if (c < 0x80 && isalnum((int)(c)))
+		if (c < 0x80 && (isalnum((int)(c)) || c=='-' || c=='_' || c=='.' || c=='~'))
 			buf_append_bytes(buf, str, 1);
+		else if (c==' ')
+			buf_append_bytes(buf, "+", 1);
 		else
 			buf_append(buf, "%%%02x", c);
 
-- 
2.7.4




More information about the openconnect-devel mailing list