Skip to content

curl_url_set with CURLUPART_URL with URL already set rejects empty string #17188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zopsicle opened this issue Apr 25, 2025 · 3 comments
Closed

Comments

@zopsicle
Copy link

I did this

auto url = curl_url();
curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
auto result = curl_url_set(url, CURLUPART_URL, "", 0);
assert(result == CURLUE_OK);

I expected the following

As per the documentation for curl_url_set:

If the handle already is populated with a URL, the new URL can be relative to the previous.

An empty string should be considered a relative URL which, when made absolute given another URL, leaves that URL untouched.

Instead, curl_url_set returns CURLUE_MALFORMED_INPUT.

curl/libcurl version

curl 8.12.1 (aarch64-unknown-linux-gnu) libcurl/8.12.1 OpenSSL/3.3.3 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.64.0
Release-Date: 2025-02-13
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

operating system

Linux utm 6.6.85 #1-NixOS SMP Fri Mar 28 20:59:57 UTC 2025 aarch64 GNU/Linux
@bagder
Copy link
Member

bagder commented Apr 25, 2025

An empty string should be considered a relative URL

Why should it be considered that?

@zopsicle
Copy link
Author

RFC 3986 4.2. Relative Reference considers an empty string a relative reference:

      relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

      relative-part = "//" authority path-abempty
                    / path-absolute
                    / path-noscheme
                    / path-empty

and the resolution algorithm (section 5.2) handles it thus:

if (R.path == "") then
    T.path = Base.path;
    ...
endif

This is also in line with the WHATWG URL spec and the behavior of web browsers when encountering <a href="".

@bagder
Copy link
Member

bagder commented Apr 25, 2025

Strong arguments, I agree.

bagder added a commit that referenced this issue Apr 25, 2025
If the CURLU handle already holds a proper URL, otherwise it is an
error.

Verified by test 1560

Fixes #17188
Reported-by: zopsicle on github
Closes #
bagder added a commit that referenced this issue Apr 25, 2025
If the CURLU handle already holds a proper URL, otherwise it is an
error.

Verified by test 1560

Fixes #17188
Reported-by: zopsicle on github
Closes #17189
@bagder bagder closed this as completed in 1583945 Apr 25, 2025
nbaws pushed a commit to nbaws/curl that referenced this issue Apr 26, 2025
If the CURLU handle already holds a proper URL, otherwise it is an
error.

Verified by test 1560

Fixes curl#17188
Reported-by: zopsicle on github
Closes curl#17189
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants