[FFmpeg-cvslog] avformat/utils: make av_url_split search for hashmark as well to separate hostname

Marton Balint git at videolan.org
Sat Feb 15 20:26:49 EET 2020


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Mon Feb  3 01:32:00 2020 +0100| [554576b6cfe79a91d37e14d3617ca417562085db] | committer: Marton Balint

avformat/utils: make av_url_split search for hashmark as well to separate hostname

RFC 3986 states that the generic syntax uses the slash ("/"), question mark
("?"), and number sign ("#") characters to delimit components that are
significant to the generic parser's hierarchical interpretation of an
identifier.

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=554576b6cfe79a91d37e14d3617ca417562085db
---

 libavformat/tests/url.c |  1 +
 libavformat/utils.c     | 14 +++-----------
 tests/ref/fate/url      |  1 +
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index d99876f02c..5e484fd428 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -75,6 +75,7 @@ int main(void)
     test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8");
     test2("ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg");
     test2("https://key.dns.com?key_id=2&model_id=12345&&access_key=");
+    test2("http://example.com#tag");
 
     return 0;
 }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index b3fbbd1942..7ff5ea9702 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4786,7 +4786,7 @@ void av_url_split(char *proto, int proto_size,
                   char *hostname, int hostname_size,
                   int *port_ptr, char *path, int path_size, const char *url)
 {
-    const char *p, *ls, *ls2, *at, *at2, *col, *brk;
+    const char *p, *ls, *at, *at2, *col, *brk;
 
     if (port_ptr)
         *port_ptr = -1;
@@ -4814,16 +4814,8 @@ void av_url_split(char *proto, int proto_size,
     }
 
     /* separate path from hostname */
-    ls = strchr(p, '/');
-    ls2 = strchr(p, '?');
-    if (!ls)
-        ls = ls2;
-    else if (ls && ls2)
-        ls = FFMIN(ls, ls2);
-    if (ls)
-        av_strlcpy(path, ls, path_size);
-    else
-        ls = &p[strlen(p)];  // XXX
+    ls = p + strcspn(p, "/?#");
+    av_strlcpy(path, ls, path_size);
 
     /* the rest is hostname, use that to parse auth/port */
     if (ls != p) {
diff --git a/tests/ref/fate/url b/tests/ref/fate/url
index 8212c1131b..980b2ce1f9 100644
--- a/tests/ref/fate/url
+++ b/tests/ref/fate/url
@@ -22,3 +22,4 @@ http://server/foo/bar?param=value/with/slashes               => http
 https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8           => https                           1l-lh.a.net        -1 /i/1LIVE_HDS at 179577/master.m3u8
 ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg                    => ftp             u:p%2B%2F2      ftp.pbt.com        -1 /ExportHD.mpg
 https://key.dns.com?key_id=2&model_id=12345&&access_key=     => https                           key.dns.com        -1 ?key_id=2&model_id=12345&&access_key=
+http://example.com#tag                                       => http                            example.com        -1 #tag



More information about the ffmpeg-cvslog mailing list