[FFmpeg-devel] [PATCH 5/5] lavu/bprint: add URL escaping

Rodger Combs rodger.combs at gmail.com
Wed Apr 12 10:11:27 EEST 2017


---
 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);
+            if (is_strictly_special ||
+                (!(flags & AV_ESCAPE_FLAG_STRICT) && !strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", *src)))
+                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, \
-- 
2.11.1



More information about the ffmpeg-devel mailing list