hyperium / http

Rust HTTP types
Apache License 2.0
1.15k stars 285 forks source link

`PartialEq`/`Ord` impls for `Authority` ignores case of userinfo part #625

Open tesaguri opened 1 year ago

tesaguri commented 1 year ago

The comparison traits are implemented for http::uri::Authority by case-insensitively comparing the underlying authority string. This works fine if the authority component only consists of the host subcomponent (and optionally the port subcomponent), which is case-insensitive according to RFC 3986 Section 6.2.2.1.

However, the authority component may also contain a (deprecated according to RFC 9110 Section 4.2.4.) userinfo subcomponent, which is not specified to be case-insensitive and thus should be compared case-sensitively. In particular, the following test should pass:

use http::uri::Authority;

#[test]
fn userinfo_eq_case_sensitive() {
    assert_ne!(
        Authority::from_static("alice:supersecurepassword@example.com"),
        Authority::from_static("Alice:SuperSecurePassword@example.com")
    );
}

But this fails with the current implementation.

Is the behavior intentional? I understand that complicating the implementation for the deprecated subcomponent might not be desirable. But I think this should at least be documented if it's intentional.