[FFmpeg-devel] [PATCH 5/5] lavu/bprint: add URL escaping
Nicolas George
george at nsup.org
Wed Apr 12 16:35:05 EEST 2017
Le tridi 23 germinal, an CCXXV, Rodger Combs a écrit :
> ---
> libavutil/avstring.h | 1 +
> libavutil/bprint.c | 11 +++++++++++
> libavutil/version.h | 2 +-
> 3 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> index 68b753a569..ccedddd210 100644
> --- a/libavutil/avstring.h
> +++ b/libavutil/avstring.h
> @@ -315,6 +315,7 @@ enum AVEscapeMode {
> AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
> AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
> AV_ESCAPE_MODE_XML, ///< Use XML ampersand-escaping; requires UTF-8 input.
> + AV_ESCAPE_MODE_URL, ///< Use URL percent-escaping
> };
>
> /**
> diff --git a/libavutil/bprint.c b/libavutil/bprint.c
> index 8e44c57346..7335acf3c9 100644
> --- a/libavutil/bprint.c
> +++ b/libavutil/bprint.c
> @@ -345,5 +345,16 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha
> }
> }
> break;
> +
> + case AV_ESCAPE_MODE_URL:
> + for (; *src; src++) {
> + int is_strictly_special = special_chars && strchr(special_chars, *src);
I think is_strictly_special is a misnomer in the existing code.
> + if (is_strictly_special ||
> + (!(flags & AV_ESCAPE_FLAG_STRICT) && !strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", *src)))
I am not entirely sure how strict escaping should work for this kind of
encoding, but there is no doubt that % itself must always be encoded.
Also, the condition you wrote would IMHO be more efficient written as:
(unsigned)((*src | 32) - 'a') < 26 ||
(unsigned)(*src - '0') < 10 ||
*src == '-' || *src == '.' || *src == '_' || *src == '~'
Last, some cases allow and prefer space to be encoded as +; since %20 is
still valid, I say we go for uniformity.
> + av_bprintf(dstbuf, "%%%02X", *src);
> + else
> + av_bprint_chars(dstbuf, *src, 1);
> + }
> + break;
> }
> }
> diff --git a/libavutil/version.h b/libavutil/version.h
> index bba39e0180..90d9137e08 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
> */
>
> #define LIBAVUTIL_VERSION_MAJOR 55
> -#define LIBAVUTIL_VERSION_MINOR 61
> +#define LIBAVUTIL_VERSION_MINOR 62
> #define LIBAVUTIL_VERSION_MICRO 100
>
> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170412/4870cdb5/attachment.sig>
More information about the ffmpeg-devel
mailing list