Re: [PATCH 11/13] strbuf: add strbuf_add*_urlencode
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 29, 2011, 18:19 UTC
- Message-ID
- <7vzkfessff.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20111124110728.GI8417@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 28 quoted lines
> This just follows the rfc3986 rules for percent-encoding
> url data into a strbuf.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> 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")?