Skip to content

Commit 554576b

Browse files
committed
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 <[email protected]>
1 parent 365b817 commit 554576b

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

libavformat/tests/url.c

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int main(void)
7575
test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8");
7676
test2("ftp://u:p%2B%[email protected]/ExportHD.mpg");
7777
test2("https://key.dns.com?key_id=2&model_id=12345&&access_key=");
78+
test2("http://example.com#tag");
7879

7980
return 0;
8081
}

libavformat/utils.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -4786,7 +4786,7 @@ void av_url_split(char *proto, int proto_size,
47864786
char *hostname, int hostname_size,
47874787
int *port_ptr, char *path, int path_size, const char *url)
47884788
{
4789-
const char *p, *ls, *ls2, *at, *at2, *col, *brk;
4789+
const char *p, *ls, *at, *at2, *col, *brk;
47904790

47914791
if (port_ptr)
47924792
*port_ptr = -1;
@@ -4814,16 +4814,8 @@ void av_url_split(char *proto, int proto_size,
48144814
}
48154815

48164816
/* separate path from hostname */
4817-
ls = strchr(p, '/');
4818-
ls2 = strchr(p, '?');
4819-
if (!ls)
4820-
ls = ls2;
4821-
else if (ls && ls2)
4822-
ls = FFMIN(ls, ls2);
4823-
if (ls)
4824-
av_strlcpy(path, ls, path_size);
4825-
else
4826-
ls = &p[strlen(p)]; // XXX
4817+
ls = p + strcspn(p, "/?#");
4818+
av_strlcpy(path, ls, path_size);
48274819

48284820
/* the rest is hostname, use that to parse auth/port */
48294821
if (ls != p) {

tests/ref/fate/url

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ http://server/foo/bar?param=value/with/slashes => http
2222
https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8 => https 1l-lh.a.net -1 /i/1LIVE_HDS@179577/master.m3u8
2323
ftp://u:p%2B%[email protected]/ExportHD.mpg => ftp u:p%2B%2F2 ftp.pbt.com -1 /ExportHD.mpg
2424
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=
25+
http://example.com#tag => http example.com -1 #tag

0 commit comments

Comments
 (0)