William,

Am 22.12.20 um 15:36 schrieb William Dauchy:
> diff --git a/doc/configuration.txt b/doc/configuration.txt
> index 95b020c03..fd8c709fa 100644
> --- a/doc/configuration.txt
> +++ b/doc/configuration.txt
> @@ -16230,6 +16230,12 @@ url_dec([<in_form>])
>    space (' '). Otherwise this will only happen after a question mark 
> indicating
>    a query string ('?').
>  
> +url_enc([<enc_type>])
> +  Takes a string provided as input and returns the encoded version as output.
> +  The input and the output are of type string. By default the type of 
> encoding
> +  is meant for `query` type. There is no other type supported for now but the
> +  optional argument is here for future changes.

Can you add a function that actually validates that the `enc_type` is
either exactly 'query' or not provided at all to make sure it catches
typos? It goes where the NULL is in `sample_conv_kw_list`.
> diff --git a/src/http_conv.c b/src/http_conv.c
> index 4afa6a2fd..b68de7aa4 100644
> --- a/src/http_conv.c
> +++ b/src/http_conv.c
> @@ -268,6 +268,36 @@ static int sample_conv_url_dec(const struct arg *args, 
> struct sample *smp, void
>       return 1;
>  }
>  
> +/* This fetch url-encode any input string. Only support query string for now 
> */
> +static int sample_conv_url_enc(const struct arg *args, struct sample *smp, 
> void
> +             *private)
> +{
> +     struct buffer *trash = get_trash_chunk();
> +     long url_encode_map[(256 / 8) / sizeof(long)];
> +     char *ret;
> +     int i;
> +
> +     /* Add final \0 required by encode_string() */
> +     smp->data.u.str.area[smp->data.u.str.data] = '\0';

I'm not sure, but is this guaranteed to have enough space for that NUL?

> +
> +     /* use rfc3986 to determine list of characters to keep unchanged for
> +      * query string */
> +     memset(url_encode_map, 0, sizeof(url_encode_map));
> +     for (i = 0; i < 256; i++) {
> +             if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')
> +                 || (i >= '0' && i <= '9') ||
> +                 i == '-' || i == '.' || i == '_' || i == '~'))
> +                     ha_bit_set(i, url_encode_map);
> +     }
> +     ret = encode_string(trash->area, trash->area + trash->size, '%',
> +                         url_encode_map, smp->data.u.str.area);
> +     if (ret == NULL || *ret != '\0')
> +             return 0;
> +     trash->data = strlen(trash->area);
> +     smp->data.u.str = *trash;
> +     return 1;
> +}
> +

Best regards
Tim Düsterhus

Reply via email to