unit1395.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 https://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 
28 static CURLcode unit_setup(void)
29 {
30  return CURLE_OK;
31 }
32 
33 static void unit_stop(void)
34 {
35 
36 }
37 
38 struct dotdot {
39  const char *input;
40  const char *output;
41 };
42 
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  { "/.../", "/.../" },
68  { "./moo", "moo" },
69  { "../moo", "moo" },
70  { "/.", "/" },
71  { "/..", "/" },
72  { "/moo/..", "/" },
73  { "..", "" },
74  { ".", "" },
75  };
76 
77  for(i = 0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
78  char *out = Curl_dedotdotify(pairs[i].input);
79  abort_unless(out != NULL, "returned NULL!");
80 
81  if(strcmp(out, pairs[i].output)) {
82  fprintf(stderr, "Test %d: '%s' gave '%s' instead of '%s'\n",
83  i, pairs[i].input, out, pairs[i].output);
84  fail("Test case output mismatched");
85  fails++;
86  }
87  else
88  fprintf(stderr, "Test %d: OK\n", i);
89  free(out);
90  }
91 
92  fail_if(fails, "output mismatched");
93 
#define free(ptr)
Definition: curl_memory.h:130
#define UNITTEST_START
Definition: curlcheck.h:86
int fails
Definition: unit1395.c:46
const char * input
Definition: unit1395.c:39
CURLcode
Definition: curl.h:454
#define abort_unless(expr, msg)
Definition: curlcheck.h:67
static CURLcode unit_setup(void)
Definition: unit1395.c:28
const char * output
Definition: unit1395.c:40
UNITTEST_START unsigned int i
Definition: unit1395.c:45
#define fail(msg)
Definition: curlcheck.h:51
const struct dotdot pairs[]
Definition: unit1395.c:47
char * Curl_dedotdotify(const char *input)
Definition: dotdot.c:53
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
fail_if(fails,"output mismatched")
#define fprintf
Definition: curl_printf.h:41
static void unit_stop(void)
Definition: unit1395.c:33


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16