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.

URL validation

From: Stephan Mühlstrasser via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 13 Jul 2020 13:41:43 +0200

Hi,

when using curl's URL functions, is it possible to validate the URL?

In the documentation of curl_url_set() it says:

"CURLUPART_URL
... The string must point to a correctly formatted "RFC 3986+" URL or be
a NULL pointer."

What exactly does "RFC 3986+" mean? And what happens if the URL string
is not a correct "RFC 3986+" URL?

Consider the following test program:

--------------------------------------------------
#include <stdio.h>
#include <curl/curl.h>

static
void
validate_url(CURLU *url_handle, const char *url)
{
     int rc = curl_url_set(url_handle, CURLUPART_URL, url, 0);

     printf("URL '%s': rc %d\n", url, rc);
}

int
main(void)
{
     CURLU *url_handle = curl_url();

     /* Valid URL: */
     validate_url(url_handle,
                 "https://curl.haxx.se/libcurl/c/curl_url_set.html");

     /* Invalid because of '<' and '>': */
     validate_url(url_handle, "https://curl.haxx.se/<invalid>");

     /* Invalid percent-escaped sequence: */
     validate_url(url_handle, "https://curl.haxx.se/%XY");

     curl_url_cleanup(url_handle);

     return 0;
}
-----------------------------------------------------

While the first URL is valid, I consider the second and third one
invalid. But curl_url_set() returns CURLUE_OK for them. Is this expected?

--
Stephan
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2020-07-13