2
0

lib1537.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2019, 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 "test.h"
  23. #include "memdebug.h"
  24. int test(char *URL)
  25. {
  26. const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  27. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
  28. CURLcode res = CURLE_OK;
  29. char *ptr = NULL;
  30. int asize;
  31. int outlen = 0;
  32. char *raw;
  33. (void)URL; /* we don't use this */
  34. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  35. fprintf(stderr, "curl_global_init() failed\n");
  36. return TEST_ERR_MAJOR_BAD;
  37. }
  38. asize = (int)sizeof(a);
  39. ptr = curl_easy_escape(NULL, (char *)a, asize);
  40. printf("%s\n", ptr);
  41. curl_free(ptr);
  42. /* deprecated API */
  43. ptr = curl_escape((char *)a, asize);
  44. printf("%s\n", ptr);
  45. if(!ptr) {
  46. res = TEST_ERR_MAJOR_BAD;
  47. goto test_cleanup;
  48. }
  49. raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen);
  50. printf("outlen == %d\n", outlen);
  51. printf("unescape == original? %s\n",
  52. memcmp(raw, a, outlen) ? "no" : "YES");
  53. curl_free(raw);
  54. /* deprecated API */
  55. raw = curl_unescape(ptr, (int)strlen(ptr));
  56. if(!raw) {
  57. res = TEST_ERR_MAJOR_BAD;
  58. goto test_cleanup;
  59. }
  60. outlen = (int)strlen(raw);
  61. printf("[old] outlen == %d\n", outlen);
  62. printf("[old] unescape == original? %s\n",
  63. memcmp(raw, a, outlen) ? "no" : "YES");
  64. curl_free(raw);
  65. curl_free(ptr);
  66. /* weird input length */
  67. ptr = curl_easy_escape(NULL, (char *)a, -1);
  68. printf("escape -1 length: %s\n", ptr);
  69. /* weird input length */
  70. outlen = 2017; /* just a value */
  71. ptr = curl_easy_unescape(NULL, (char *)"moahahaha", -1, &outlen);
  72. printf("unescape -1 length: %s %d\n", ptr, outlen);
  73. test_cleanup:
  74. curl_free(ptr);
  75. curl_global_cleanup();
  76. return (int)res;
  77. }