servo / servo/rust-url

Feature request: append a directory as the fragment, and turn the last path segment into directory

Open
#733 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
406
PR merge metrics
No merged PRs in 30d

Description

It is sometimes useful to "join" the directory to the url without specifying the last slash. For example,

let url = Url::parse("https://example.com/")?;
let dir = "dir";
let new_url = url.join_dir(dir)?;  // cool!

instead of

let url = Url::parse("https://example.com/")?;
let dir = "dir";
let new_url = url.join(&(dir + "/"))?;  // ugly!

would be good.

It is also useful to turn the last path segment to directory. For example

let mut url = Url::parse("https://example.com/child");
if url.path.ends_with('/') {   // looks bad
  url.set_path(&(url.path() + "/"));
}

could be replaced with something like

let url = Url::parse("https://example.com/child");
let url = url.ensure_dir();

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing Url::join, path, and set_path entry points to understand URL path resolution and mutation. Add the requested directory-joining and trailing-directory behavior, then run the repository's existing tests and cover the examples in the issue; done means both operations work without manually appending a slash.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.