Thread (41 messages) 41 messages, 6 authors, 2016-06-15

Re: [PATCH 11/13] strbuf: add strbuf_add*_urlencode

flat view

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:32

Jeff King [off-list ref] writes:
quoted hunk ↗ jump to hunk
This just follows the rfc3986 rules for percent-encoding
url data into a strbuf.

Signed-off-by: Jeff King <redacted>
---
 strbuf.c |   37 +++++++++++++++++++++++++++++++++++++
 strbuf.h |    5 +++++
 2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index 3ad2cc0..60e5e59 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -397,3 +397,40 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
 
 	return len;
 }
+
+static int is_rfc3986_reserved(char ch)
+{
+	switch (ch) {
+	case '!': case '*': case '\'': case '(': case ')': case ';':
+	case ':': case '@': case '&': case '=': case '+': case '$':
+	case ',': case '/': case '?': case '#': case '[': case ']':
+		return 1;
+	}
+	return 0;
+}
Part of me wonders if we still have extra bits in sane_ctype[] array but
that one is cumbersome to update, and the above should be easier to read
and maintain.
+void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len,
+			  int reserved)
Does "reserved" parameter mean "must-encode-reserved", or
"may-encode-reserved" (the latter would be more like "if set to 0,
per-cent encoding the result would be an error")?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help