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

Disabling "remove dot segments" behavior #874

Open
jwodder opened this issue Oct 23, 2023 · 2 comments
Open

Disabling "remove dot segments" behavior #874

jwodder opened this issue Oct 23, 2023 · 2 comments

Comments

@jwodder
Copy link

jwodder commented Oct 23, 2023

I have a use-case where I need to be able to construct URLs that end in …/. or …/..1; however, the url crate insists on removing dot segments no matter what API I go through, even when the dots are percent-escaped, e.g.:

fn main() {
    let url = url::Url::parse("https://example.com/path/%2e%2e").unwrap();
    // Prints "https://example.com/":
    println!("{url}");
}

Is there currently a method to construct a URL like this using this crate? If not, could such a method be added?

Footnotes

  1. Specifically, this is for manipulating GitHub labels via the GitHub REST API; if a user names a label with dot or dot-dot, the URL ends up with dots at the end.

@valenting
Copy link
Collaborator

This replacement is mandated by the URL standard, so I'd be slightly surprised if the server side doesn't parse the URLs in a similar way.
Have a look at whether encoding the % sign works, so instead of %2e use %252e


use url::Url;

fn main() {
    let bs: &str = "https://example.org/path_to_replace";
    let mut base = Url::parse(bs).unwrap();
    base.path_segments_mut().unwrap().pop().push("%2e%2e");
    println!("{:?}", base); // prints path: "/%252e%252e"
}

@jwodder
Copy link
Author

jwodder commented Oct 24, 2023

@valenting Testing GitHub's REST API via curl, curl https://api.github.com/repos/jwodder/test/labels/.. and …/labels/%252e%252e both result in 404; only …/labels/%2e%2e works.

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

No branches or pull requests

2 participants