unit1395.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
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


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07