00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #include "dotdot.h"
00025
00026 #include "memdebug.h"
00027
00028 static CURLcode unit_setup(void)
00029 {
00030 return CURLE_OK;
00031 }
00032
00033 static void unit_stop(void)
00034 {
00035
00036 }
00037
00038 struct dotdot {
00039 const char *input;
00040 const char *output;
00041 };
00042
00043 UNITTEST_START
00044
00045 unsigned int i;
00046 int fails=0;
00047 const struct dotdot pairs[] = {
00048 { "/a/b/c/./../../g", "/a/g" },
00049 { "mid/content=5/../6", "mid/6" },
00050 { "/hello/../moo", "/moo" },
00051 { "/1/../1", "/1" },
00052 { "/1/./1", "/1/1" },
00053 { "/1/..", "/" },
00054 { "/1/.", "/1/" },
00055 { "/1/./..", "/" },
00056 { "/1/./../2", "/2" },
00057 { "/hello/1/./../2", "/hello/2" },
00058 { "test/this", "test/this" },
00059 { "test/this/../now", "test/now" },
00060 { "/1../moo../foo", "/1../moo../foo"},
00061 { "/../../moo", "/moo"},
00062 { "/../../moo?andnot/../yay", "/moo?andnot/../yay"},
00063 { "/123?foo=/./&bar=/../", "/123?foo=/./&bar=/../"},
00064 { "/../moo/..?what", "/?what" },
00065 { "/", "/" },
00066 { "", "" },
00067 { "/.../", "/.../" },
00068 };
00069
00070 for(i=0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
00071 char *out = Curl_dedotdotify((char *)pairs[i].input);
00072 abort_unless(out != NULL, "returned NULL!");
00073
00074 if(strcmp(out, pairs[i].output)) {
00075 fprintf(stderr, "Test %d: '%s' gave '%s' instead of '%s'\n",
00076 i, pairs[i].input, out, pairs[i].output);
00077 fail("Test case output mismatched");
00078 fails++;
00079 }
00080 else
00081 fprintf(stderr, "Test %d: OK\n", i);
00082 free(out);
00083 }
00084
00085 fail_if(fails, "output mismatched");
00086
00087 UNITTEST_STOP