1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at http://curl.haxx.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ***************************************************************************/ 22#include "curlcheck.h" 23 24#include "dotdot.h" 25 26#include "memdebug.h" 27 28static CURLcode unit_setup(void) 29{ 30 return CURLE_OK; 31} 32 33static void unit_stop(void) 34{ 35 36} 37 38struct dotdot { 39 const char *input; 40 const char *output; 41}; 42 43UNITTEST_START 44 45 unsigned int i; 46 int fails=0; 47 const struct dotdot pairs[] = { 48 { "/a/b/c/./../../g", "/a/g" }, 49 { "mid/content=5/../6", "mid/6" }, 50 { "/hello/../moo", "/moo" }, 51 { "/1/../1", "/1" }, 52 { "/1/./1", "/1/1" }, 53 { "/1/..", "/" }, 54 { "/1/.", "/1/" }, 55 { "/1/./..", "/" }, 56 { "/1/./../2", "/2" }, 57 { "/hello/1/./../2", "/hello/2" }, 58 { "test/this", "test/this" }, 59 { "test/this/../now", "test/now" }, 60 { "/1../moo../foo", "/1../moo../foo"}, 61 { "/../../moo", "/moo"}, 62 { "/../../moo?andnot/../yay", "/moo?andnot/../yay"}, 63 { "/123?foo=/./&bar=/../", "/123?foo=/./&bar=/../"}, 64 { "/../moo/..?what", "/?what" }, 65 }; 66 67 for(i=0; i < sizeof(pairs)/sizeof(pairs[0]); i++) { 68 char *out = Curl_dedotdotify((char *)pairs[i].input); 69 abort_unless(out != NULL, "returned NULL!"); 70 71 if(strcmp(out, pairs[i].output)) { 72 fprintf(stderr, "Test %d: '%s' gave '%s' instead of '%s'\n", 73 i, pairs[i].input, out, pairs[i].output); 74 fail("Test case output mismatched"); 75 fails++; 76 } 77 else 78 fprintf(stderr, "Test %d: OK\n", i); 79 free(out); 80 } 81 82 fail_if(fails, "output mismatched"); 83 84UNITTEST_STOP 85