]> git.sesse.net Git - ffmpeg/commitdiff
avformat/urldecode: add the ability to not decode plus sign to space
authorMarton Balint <cus@passwd.hu>
Tue, 4 Feb 2020 22:44:28 +0000 (23:44 +0100)
committerMarton Balint <cus@passwd.hu>
Sat, 15 Feb 2020 17:41:36 +0000 (18:41 +0100)
Signed-off-by: Marton Balint <cus@passwd.hu>
libavformat/httpauth.c
libavformat/urldecode.c
libavformat/urldecode.h

index 2d42ab2190c8c4e9b637d4e8240c7e1618ff0887..54d0322c6ae1a16322f07730d754e141ff179c70 100644 (file)
@@ -255,7 +255,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth,
 
     if (state->auth_type == HTTP_AUTH_BASIC) {
         int auth_b64_len, len;
-        char *ptr, *decoded_auth = ff_urldecode(auth);
+        char *ptr, *decoded_auth = ff_urldecode(auth, 1);
 
         if (!decoded_auth)
             return NULL;
@@ -275,7 +275,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth,
         av_strlcat(ptr, "\r\n", len - (ptr - authstr));
         av_free(decoded_auth);
     } else if (state->auth_type == HTTP_AUTH_DIGEST) {
-        char *username = ff_urldecode(auth), *password;
+        char *username = ff_urldecode(auth, 1), *password;
 
         if (!username)
             return NULL;
index 283d9126716e46f6116d2431c2dbb654a22601df..5261bcd0cd88e2c7a2bcef52d735df2ef18146ca 100644 (file)
@@ -32,7 +32,7 @@
 #include "libavutil/avstring.h"
 #include "urldecode.h"
 
-char *ff_urldecode(const char *url)
+char *ff_urldecode(const char *url, int decode_plus_sign)
 {
     int s = 0, d = 0, url_len = 0;
     char c;
@@ -74,7 +74,7 @@ char *ff_urldecode(const char *url)
                 dest[d++] = c2;
                 dest[d++] = c3;
             }
-        } else if (c == '+') {
+        } else if (c == '+' && decode_plus_sign) {
             dest[d++] = ' ';
         } else {
             dest[d++] = c;
index cb81ebc6f79f3f30db9b968c71199020f3779a45..80b11c342869313eeded172cfeeb79fef2de557a 100644 (file)
  * in that case the original string is duplicated.
  *
  * @param url a string to be decoded.
+ * @param decode_plus_sign if nonzero plus sign is decoded to space
  * @return new string with the URL decoded or NULL if decoding failed.
  * Note that the returned string should be explicitly freed when not
  * used anymore.
  */
-char *ff_urldecode(const char *url);
+char *ff_urldecode(const char *url, int decode_plus_sign);
 
 #endif /* AVFORMAT_URLDECODE_H */