hyperium / hyperium/http

Uri Builder path change broke parsing and reconstructing the Uri with empty path

Open
#846 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.4k
Forks
378
Avg merge
1d 21h
Merged PRs (30d)
5

Description

Version

http v1.4.1

Platform

Linux 6.8.0-111-generic Ubuntu 24.04

Summary

Uri Builder path change broke parsing and reconstructing the Uri with empty path.
In example below the path returns empty string.

This used to work fine to sanitize/cleanup a provided Url string, which I think is a common pattern people use.

As Uri.path() always returns a string and not an Option<String> its not intuitive that this stops working.

Also what is a bit annoying is that this broke in a patch update version.
Took me a while to figure out that an auto update of this dependency broke this behavior.

Code Sample
    let uri = Uri::from_str("example.com")?;
    let final_uri = Uri::builder()
        .scheme(uri.scheme_str().unwrap_or("https"))
        .authority(uri.authority()?.as_str())
        .path_and_query(uri.path())
        .build();
Expected Behavior

In v1.4.0 this used to work.

final_uri = Ok(Uri(...))
Actual Behavior

Since v1.4.1 this fails now.

final_uri = Err(http::Error(InvalidUri(Empty)))
Additional Context

If this is just intended and works as designed then feel free to close this.

Workaround I needed to add:

    let path = if !path.starts_with("/") {
        "/".to_string() + path
    } else {
        path.to_string()
    };

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 with the Uri::builder path_and_query handling shown in the issue and compare its behavior between http v1.4.0 and v1.4.1. Add a regression test for rebuilding a Uri with an empty path, then run the relevant Uri builder and parsing tests to confirm the example succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.