History

avformat/url: add ff_make_absolulte_url2 to be able to test windows path cases

Marton Balint committed 5 years ago

Commit fb4da901 parent 5dc5f284 files · +69 −6Browse files

Unified · Split

4 files
  1. libavformat/tests/url.c +30 −3
  2. libavformat/url.c +9 −3
  3. libavformat/url.h +10 −0
  4. tests/ref/fate/url +20 −0
libavformat/tests/url.c+30−3
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
21+#include "config.h"
2122 #include "libavformat/url.h"
2223 #include "libavformat/avformat.h"
2324
@@ -48,19 +49,30 @@ static void test_decompose(const char *url) · 24 unmodified lines
4849
4950 static void test(const char *base, const char *rel)
5051 {
51− char buf[200], buf2[200];
52+ char buf[200], buf2[200], buf_dos[200], buf_native[200];
5253 int ret;
5354
54− ret = ff_make_absolute_url(buf, sizeof(buf), base, rel);
55+ ret = ff_make_absolute_url2(buf, sizeof(buf), base, rel, 0);
5556 if (ret < 0) {
5657 printf("%50s %-20s => error %s\n", base, rel, av_err2str(ret));
5758 return;
5859 }
5960 printf("%50s %-20s => %s\n", base, rel, buf);
61+ ret = ff_make_absolute_url2(buf_dos, sizeof(buf_dos), base, rel, 1);
62+ if (ret < 0)
63+ snprintf(buf_dos, sizeof(buf_dos), "error %s", av_err2str(ret));
64+ ret = ff_make_absolute_url(buf_native, sizeof(buf_native), base, rel);
65+ if (ret < 0)
66+ snprintf(buf_native, sizeof(buf_native), "error %s", av_err2str(ret));
67+ if (strcmp(buf, buf_dos))
68+ printf("%50s %-20sDOS %s\n", base, rel, buf_dos);
69+ if (HAVE_DOS_PATHS && strcmp(buf_dos, buf_native) ||
70+ !HAVE_DOS_PATHS && strcmp(buf, buf_native))
71+ printf("Native mismatch\n");
6072 if (base) {
6173 /* Test in-buffer replacement */
6274 snprintf(buf2, sizeof(buf2), "%s", base);
63− ff_make_absolute_url(buf2, sizeof(buf2), buf2, rel);
75+ ff_make_absolute_url2(buf2, sizeof(buf2), buf2, rel, 0);
6476 if (strcmp(buf, buf2)) {
6577 printf("In-place handling of %s + %s failed\n", base, rel);
6678 exit(1);
@@ -121,6 +133,21 @@ int main(void) · 54 unmodified lines
121133 test("http://server/foo/bar", "..doubledotfile");
122134 test("http://server/foo/bar", "double..dotfile");
123135 test("http://server/foo/bar", "doubledotfile..");
136+ test("file1", "file2");
137+ test("dir/file1", "file2");
138+ test("dir/file1", "../file2");
139+ test("dir\\file1", "file2");
140+ test("\\\\srv\\shr\\file", "..\\..\\dummy");
141+ test("\\\\srv\\shr\\file", "dummy");
142+ test("\\\\srv\\shr\\file", "\\\\srv2\\shr2\\file2");
143+ test("\\\\srv\\shr\\file", "d:/file");
144+ test("C:\\dir\\a", "..\\file");
145+ test("C:\\dir\\a", "\\\\srv\\shr\\file");
146+ test("C:\\dir\\a", "d:\\file");
147+ test("http://a/b", "\\\\srv\\shr\\file");
148+ test("http://a/b", "//srv/shr/file");
149+ test("http://a/b", "d:\\file");
150+ test("http://a/b", "C:/file");
124151
125152 /* From https://tools.ietf.org/html/rfc3986#section-5.4 */
126153 test("http://a/b/c/d;p?q", "g:h"); // g:h
libavformat/url.c+9−3
@@ -190,8 +190,8 @@ static int append_path(char *root, char *out_end, char **rout, · 189 unmodified lines
190190 return 0;
191191 }
192192
193−int ff_make_absolute_url(char *buf, int size, const char *base,
194− const char *rel)
193+int ff_make_absolute_url2(char *buf, int size, const char *base,
194+ const char *rel, int handle_dos_paths)
195195 {
196196 URLComponents ub, uc;
197197 char *out, *out_end, *path;
@@ -224,7 +224,7 @@ int ff_make_absolute_url(char *buf, int size, const char *base, · 26 unmodified lines
224224
225225 if (!base)
226226 base = "";
227− if (HAVE_DOS_PATHS) {
227+ if (handle_dos_paths) {
228228 if ((ret = ff_url_decompose(&ub, base, NULL)) < 0)
229229 goto error;
230230 if (is_fq_dos_path(base) || av_strstart(base, "file:", NULL) || ub.path == ub.url) {
@@ -316,6 +316,12 @@ error: · 85 unmodified lines
316316 return ret;
317317 }
318318
319+int ff_make_absolute_url(char *buf, int size, const char *base,
320+ const char *rel)
321+{
322+ return ff_make_absolute_url2(buf, size, base, rel, HAVE_DOS_PATHS);
323+}
324+
319325 AVIODirEntry *ff_alloc_dir_entry(void)
320326 {
321327 AVIODirEntry *entry = av_mallocz(sizeof(AVIODirEntry));
libavformat/url.h+10−0
@@ -308,6 +308,16 @@ int ff_url_join(char *str, int size, const char *proto, · 307 unmodified lines
308308 * @param size the size of buf
309309 * @param base the base url, may be equal to buf.
310310 * @param rel the new url, which is interpreted relative to base
311+ * @param handle_dos_paths handle DOS paths for file or unspecified protocol
312+ */
313+int ff_make_absolute_url2(char *buf, int size, const char *base,
314+ const char *rel, int handle_dos_paths);
315+
316+/**
317+ * Convert a relative url into an absolute url, given a base url.
318+ *
319+ * Same as ff_make_absolute_url2 with handle_dos_paths being equal to
320+ * HAVE_DOS_PATHS config variable.
311321 */
312322 int ff_make_absolute_url(char *buf, int size, const char *base,
313323 const char *rel);
tests/ref/fate/url+20−0
@@ -79,6 +79,26 @@ Testing ff_make_absolute_url: · 78 unmodified lines
7979 http://server/foo/bar ..doubledotfile => http://server/foo/..doubledotfile
8080 http://server/foo/bar double..dotfile => http://server/foo/double..dotfile
8181 http://server/foo/bar doubledotfile.. => http://server/foo/doubledotfile..
82+ file1 file2 => file2
83+ dir/file1 file2 => dir/file2
84+ dir/file1 ../file2 => dir/../file2
85+ dir\file1 file2 => file2
86+ dir\file1 file2 DOS dir\file2
87+ \\srv\shr\file ..\..\dummy => ..\..\dummy
88+ \\srv\shr\file ..\..\dummy DOS \\srv\shr\..\..\dummy
89+ \\srv\shr\file dummy => dummy
90+ \\srv\shr\file dummy DOS \\srv\shr\dummy
91+ \\srv\shr\file \\srv2\shr2\file2 => \\srv2\shr2\file2
92+ \\srv\shr\file d:/file => d:/file
93+ C:\dir\a ..\file => C:..\file
94+ C:\dir\a ..\file DOS C:\dir\..\file
95+ C:\dir\a \\srv\shr\file => C:\\srv\shr\file
96+ C:\dir\a \\srv\shr\file DOS \\srv\shr\file
97+ C:\dir\a d:\file => d:\file
98+ http://a/b \\srv\shr\file => http://a/\\srv\shr\file
99+ http://a/b //srv/shr/file => http://srv/shr/file
100+ http://a/b d:\file => d:\file
101+ http://a/b C:/file => C:/file
82102 http://a/b/c/d;p?q g:h => g:h
83103 http://a/b/c/d;p?q g => http://a/b/c/g
84104 http://a/b/c/d;p?q ./g => http://a/b/c/g

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t