summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-19 16:05:16 -0800
committerJunio C Hamano <gitster@pobox.com>2011-12-19 16:05:16 -0800
commit367d20ec6b9e8e297537f665fb528346bd0aff27 (patch)
treebce97747bf55c8b3adffa0a058984aba5ea3225f /strbuf.c
parentd16520499d2652b5b59dfb25f9cf2d56a4c6913a (diff)
parent861444f6d702b15713d0875ce9dc5aff64885fba (diff)
downloadgit-367d20ec6b9e8e297537f665fb528346bd0aff27.tar.gz
Merge branch 'jk/credentials'
* jk/credentials: t: add test harness for external credential helpers credentials: add "store" helper strbuf: add strbuf_add*_urlencode Makefile: unix sockets may not available on some platforms credentials: add "cache" helper docs: end-user documentation for the credential subsystem credential: make relevance of http path configurable credential: add credential.*.username credential: apply helper config http: use credential API to get passwords credential: add function for parsing url components introduce credentials API t5550: fix typo test-lib: add test_config_global variant Conflicts: strbuf.c
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index a849705197..ff0b96b416 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -411,3 +411,40 @@ void strbuf_add_lines(struct strbuf *out, const char *prefix,
}
strbuf_complete_line(out);
}
+
+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;
+}
+
+static int is_rfc3986_unreserved(char ch)
+{
+ return isalnum(ch) ||
+ ch == '-' || ch == '_' || ch == '.' || ch == '~';
+}
+
+void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len,
+ int reserved)
+{
+ strbuf_grow(sb, len);
+ while (len--) {
+ char ch = *s++;
+ if (is_rfc3986_unreserved(ch) ||
+ (!reserved && is_rfc3986_reserved(ch)))
+ strbuf_addch(sb, ch);
+ else
+ strbuf_addf(sb, "%%%02x", ch);
+ }
+}
+
+void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
+ int reserved)
+{
+ strbuf_add_urlencode(sb, s, strlen(s), reserved);
+}