Skip to content
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

Parsing anchor links changes path/query of URL #15836

Closed
jeroen opened this issue Dec 27, 2024 · 1 comment
Closed

Parsing anchor links changes path/query of URL #15836

jeroen opened this issue Dec 27, 2024 · 1 comment
Assignees
Labels

Comments

@jeroen
Copy link
Contributor

jeroen commented Dec 27, 2024

I did this

When parsing anchor-only links #section from a html page, the path and query sometimes change. For example:

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

int main(void){
  curl_global_init(CURL_GLOBAL_DEFAULT);
  CURLU *h = curl_url();
  curl_url_set(h, CURLUPART_URL, "https://x.com/a/b/c?x=123", 0); //base url
  curl_url_set(h, CURLUPART_URL, "#bar", 0); //href
  char *str = NULL;
  CURLUcode err = curl_url_get(h, CURLUPART_URL, &str, 0);
  printf("%s\n", str);
  return 0;
}

I think the correct value here should be https://x.com/a/b/c?x=123#bar.

However on MacOS (curl 8.7.1) it is: https://x.com/a/b/#bar (both the path and query have changed).

On Debian Linux (8.11.1) it is: https://x.com/a/b/c#bar (the query has changed).

I expected the following

The url with #bar appended and no changes to the path or query.

curl/libcurl version

curl 8.11.1

operating system

MacOS / Debian

@bagder bagder self-assigned this Dec 27, 2024
@bagder bagder added the URL label Dec 27, 2024
jeroen added a commit to jeroen/curl that referenced this issue Dec 27, 2024
bagder added a commit that referenced this issue Dec 28, 2024
The redirect logic was broken when the redirect-to URL was a relative
URL as a fragment only (starting with '#').

Extended test 1560 to reproduce, then verify.

Reported-by: Jeroen Ooms
Fixes #15836
Closes #
bagder added a commit that referenced this issue Dec 29, 2024
The redirect logic was broken when the redirect-to URL was a relative
URL only as a fragment or query (starting with '#' or '?').

Extended test 1560 to reproduce, then verify.

Reported-by: Jeroen Ooms
Fixes #15836
Closes #15848
@bagder bagder closed this as completed in 66e5351 Dec 30, 2024
@jeroen
Copy link
Contributor Author

jeroen commented Dec 30, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants