curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Escaping URL for CURLOPT_URL

From: Daniel Stenberg via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 20 Apr 2022 23:10:47 +0200 (CEST)

On Wed, 20 Apr 2022, Andreas Falkenhahn via curl-library wrote:

> is there any convenient way of escaping a URL so that it can be passed to
> CURLOPT_URL?

The main problem with "URL-escaping a URL" which makes it hard to offer as a
feature, is that it is an oxymoron.

A URL is by definition already URL encoded/escaped. If it isn't, it isn't a
legal URL.

You are actually in more technically correct terms asking for a way to
"transcode an almost-URL string into a proper URL", which is a "do what I
mean" style mission since there is no strict rules or guidelines for this.

In the specific case you showed us you had a space in the string, so then I
*assume* you want that encoded is %20 in the URL? That seems like something
you can do rather easily yourself. But if you go beyond that and have other
things that aren't valid URL characters in the string, should they also just
be converted to the their %HH-alternatives or do they need other treatment?

(The URL API option mentioned previously does that encode all illegal
characters as %HH.)

-- 
  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-04-20