cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: escaping a url?

From: csapuntz <csapuntz_at_gmail.com>
Date: Thu, 24 Sep 2009 07:19:26 -0700

On Thu, Sep 24, 2009 at 6:28 AM, Jonathan Wallace <
jwallace_at_livetechnology.com> wrote:

> Is there a way to url encode a url? When I try to use curl_easy_escape it
> handles the domain too, causing the request to fail.
>

Let's see if I understand what you're asking: is there a way to take a
string that looks a lot like a url but doesn't match the RFC rules and
turn it into something that matches the RFC rules? Because a valid url
should be by definition properly url encoded. I.e. there is no such thing
as a non-url encoded url.

In reality, users enter all sorts of weird stuff. Some cleanups that can be
done on an almost-url:
  - convert spaces to %20
  - convert % not followed by two hex digits to %25
  - convert character below ascii 33 and above 126 to %xx representation

curl_easy_escape is not the function to do those cleanups. My org ended up
writing its own.

If what you want to do is embed the URL as query parameter, then you should
consider URL-encoding the URL. For example:

http://first/redirect?dst=http%3A%2F%2Fsecond%2F

-Costa

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-09-24