xref: /curl/docs/libcurl/curl_unescape.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_unescape
5Section: 3
6Source: libcurl
7See-also:
8  - RFC 2396
9  - curl_easy_escape (3)
10  - curl_easy_unescape (3)
11  - curl_free (3)
12Protocol:
13  - All
14---
15
16# NAME
17
18curl_unescape - URL decodes the given string
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25char *curl_unescape(const char *input, int length);
26~~~
27
28# DESCRIPTION
29
30Obsolete function. Use curl_easy_unescape(3) instead.
31
32This function converts the URL encoded string **input** to a "plain string"
33and return that as a new allocated string. All input characters that are URL
34encoded (%XX where XX is a two-digit hexadecimal number) are converted to
35their plain text versions.
36
37If the **length** argument is set to 0, curl_unescape(3) calls
38strlen() on **input** to find out the size.
39
40You must curl_free(3) the returned string when you are done with it.
41
42# EXAMPLE
43
44~~~c
45int main(void)
46{
47  CURL *curl = curl_easy_init();
48  if(curl) {
49    char *decoded = curl_unescape("%63%75%72%6c", 12);
50    if(decoded) {
51      /* do not assume printf() works on the decoded data */
52      printf("Decoded: ");
53      /* ... */
54      curl_free(decoded);
55    }
56  }
57}
58~~~
59
60# AVAILABILITY
61
62Since 7.15.4, curl_easy_unescape(3) should be used. This function might
63be removed in a future release.
64
65# RETURN VALUE
66
67A pointer to a null-terminated string or NULL if it failed.
68