unit1395.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "dotdot.h"
  24. #include "memdebug.h"
  25. static CURLcode unit_setup(void)
  26. {
  27. return CURLE_OK;
  28. }
  29. static void unit_stop(void)
  30. {
  31. }
  32. struct dotdot {
  33. const char *input;
  34. const char *output;
  35. };
  36. UNITTEST_START
  37. unsigned int i;
  38. int fails=0;
  39. const struct dotdot pairs[] = {
  40. { "/a/b/c/./../../g", "/a/g" },
  41. { "mid/content=5/../6", "mid/6" },
  42. { "/hello/../moo", "/moo" },
  43. { "/1/../1", "/1" },
  44. { "/1/./1", "/1/1" },
  45. { "/1/..", "/" },
  46. { "/1/.", "/1/" },
  47. { "/1/./..", "/" },
  48. { "/1/./../2", "/2" },
  49. { "/hello/1/./../2", "/hello/2" },
  50. { "test/this", "test/this" },
  51. { "test/this/../now", "test/now" },
  52. { "/1../moo../foo", "/1../moo../foo"},
  53. { "/../../moo", "/moo"},
  54. { "/../../moo?andnot/../yay", "/moo?andnot/../yay"},
  55. { "/123?foo=/./&bar=/../", "/123?foo=/./&bar=/../"},
  56. { "/../moo/..?what", "/?what" },
  57. };
  58. for(i=0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
  59. char *out = Curl_dedotdotify((char *)pairs[i].input);
  60. abort_unless(out != NULL, "returned NULL!");
  61. if(strcmp(out, pairs[i].output)) {
  62. fprintf(stderr, "Test %d: '%s' gave '%s' instead of '%s'\n",
  63. i, pairs[i].input, out, pairs[i].output);
  64. fail("Test case output mismatched");
  65. fails++;
  66. }
  67. else
  68. fprintf(stderr, "Test %d: OK\n", i);
  69. free(out);
  70. }
  71. fail_if(fails, "output mismatched");
  72. UNITTEST_STOP