| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
|  | 2 | *                                  _   _ ____  _ | 
|  | 3 | *  Project                     ___| | | |  _ \| | | 
|  | 4 | *                             / __| | | | |_) | | | 
|  | 5 | *                            | (__| |_| |  _ <| |___ | 
|  | 6 | *                             \___|\___/|_| \_\_____| | 
|  | 7 | * | 
|  | 8 | * Copyright (C) 1998 - 2022, 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.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 | * SPDX-License-Identifier: curl | 
|  | 22 | * | 
|  | 23 | ***************************************************************************/ | 
|  | 24 | #include "curlcheck.h" | 
|  | 25 |  | 
|  | 26 | /* copied from urlapi.c */ | 
|  | 27 | extern char *dedotdotify(const char *input, size_t clen); | 
|  | 28 |  | 
|  | 29 | #include "memdebug.h" | 
|  | 30 |  | 
|  | 31 | static CURLcode unit_setup(void) | 
|  | 32 | { | 
|  | 33 | return CURLE_OK; | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | static void unit_stop(void) | 
|  | 37 | { | 
|  | 38 |  | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | struct dotdot { | 
|  | 42 | const char *input; | 
|  | 43 | const char *output; | 
|  | 44 | }; | 
|  | 45 |  | 
|  | 46 | UNITTEST_START | 
|  | 47 |  | 
|  | 48 | unsigned int i; | 
|  | 49 | int fails = 0; | 
|  | 50 | const struct dotdot pairs[] = { | 
|  | 51 | { "/a/b/c/./../../g", "/a/g" }, | 
|  | 52 | { "mid/content=5/../6", "mid/6" }, | 
|  | 53 | { "/hello/../moo", "/moo" }, | 
|  | 54 | { "/1/../1", "/1" }, | 
|  | 55 | { "/1/./1", "/1/1" }, | 
|  | 56 | { "/1/..", "/" }, | 
|  | 57 | { "/1/.", "/1/" }, | 
|  | 58 | { "/1/./..", "/" }, | 
|  | 59 | { "/1/./../2", "/2" }, | 
|  | 60 | { "/hello/1/./../2", "/hello/2" }, | 
|  | 61 | { "test/this", "test/this" }, | 
|  | 62 | { "test/this/../now", "test/now" }, | 
|  | 63 | { "/1../moo../foo", "/1../moo../foo"}, | 
|  | 64 | { "/../../moo", "/moo"}, | 
|  | 65 | { "/../../moo?andnot/../yay", "/moo?andnot/../yay"}, | 
|  | 66 | { "/123?foo=/./&bar=/../", "/123?foo=/./&bar=/../"}, | 
|  | 67 | { "/../moo/..?what", "/?what" }, | 
|  | 68 | { "/", "/" }, | 
|  | 69 | { "", "" }, | 
|  | 70 | { "/.../", "/.../" }, | 
|  | 71 | { "./moo", "moo" }, | 
|  | 72 | { "../moo", "moo" }, | 
|  | 73 | { "/.", "/" }, | 
|  | 74 | { "/..", "/" }, | 
|  | 75 | { "/moo/..", "/" }, | 
|  | 76 | { "..", "" }, | 
|  | 77 | { ".", "" }, | 
|  | 78 | }; | 
|  | 79 |  | 
|  | 80 | for(i = 0; i < sizeof(pairs)/sizeof(pairs[0]); i++) { | 
|  | 81 | char *out = dedotdotify(pairs[i].input, strlen(pairs[i].input)); | 
|  | 82 | abort_unless(out != NULL, "returned NULL!"); | 
|  | 83 |  | 
|  | 84 | if(strcmp(out, pairs[i].output)) { | 
|  | 85 | fprintf(stderr, "Test %u: '%s' gave '%s' instead of '%s'\n", | 
|  | 86 | i, pairs[i].input, out, pairs[i].output); | 
|  | 87 | fail("Test case output mismatched"); | 
|  | 88 | fails++; | 
|  | 89 | } | 
|  | 90 | else | 
|  | 91 | fprintf(stderr, "Test %u: OK\n", i); | 
|  | 92 | free(out); | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | fail_if(fails, "output mismatched"); | 
|  | 96 |  | 
|  | 97 | UNITTEST_STOP |