1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 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 /* Based on Alex Fishman's bug report on September 30, 2007 */
25
26 #include "test.h"
27
28 #include "memdebug.h"
29
test(char * URL)30 CURLcode test(char *URL)
31 {
32 static const unsigned char a[] = {
33 0x9c, 0x26, 0x4b, 0x3d, 0x49, 0x4, 0xa1, 0x1,
34 0xe0, 0xd8, 0x7c, 0x20, 0xb7, 0xef, 0x53, 0x29, 0xfa,
35 0x1d, 0x57, 0xe1};
36
37 CURL *easy;
38 CURLcode res = CURLE_OK;
39 (void)URL;
40
41 global_init(CURL_GLOBAL_ALL);
42 easy = curl_easy_init();
43 if(!easy) {
44 fprintf(stderr, "curl_easy_init() failed\n");
45 res = TEST_ERR_MAJOR_BAD;
46 }
47 else {
48 int asize = (int)sizeof(a);
49 char *s = curl_easy_escape(easy, (const char *)a, asize);
50
51 if(s) {
52 printf("%s\n", s);
53 curl_free(s);
54 }
55
56 s = curl_easy_escape(easy, "", 0);
57 if(s) {
58 printf("IN: '' OUT: '%s'\n", s);
59 curl_free(s);
60 }
61 s = curl_easy_escape(easy, " 123", 3);
62 if(s) {
63 printf("IN: ' 12' OUT: '%s'\n", s);
64 curl_free(s);
65 }
66
67 curl_easy_cleanup(easy);
68 }
69 curl_global_cleanup();
70
71 return res;
72 }
73