Skip to content

Conversation

valenting
Copy link
Collaborator

This fixes a regression from #1021

#[test]
fn test_parse_url_with_single_byte_control_host() {
    let input = "l://\x01:";

    let url1 = Url::parse(input).unwrap();
    let url2 = Url::parse(url1.as_str()).unwrap();
    assert_eq!(url2, url1);
}

The problem is that the code at:

rust-url/url/src/host.rs

Lines 157 to 161 in 22b925f

match utf8_percent_encode(&input, CONTROLS).into() {
Cow::Owned(v) => Cow::Owned(v),
// if we're borrowing, then we can return the original Cow
Cow::Borrowed(_) => input,
},

assumed Cow::Borrowed means no percent-encoding happened, but for single byte controls we do get a Cow::Borrowed from the static encoding table

@valenting valenting requested a review from hsivonen October 6, 2025 12:23
@valenting valenting enabled auto-merge October 6, 2025 12:38
@valenting valenting requested a review from Manishearth October 6, 2025 12:38
@valenting valenting added this pull request to the merge queue Oct 6, 2025
Merged via the queue into main with commit 9771ab5 Oct 6, 2025
16 checks passed
Cow::Owned(v) => Cow::Owned(v),
// If we're borrowing, we need to check if it's the same as the input
Cow::Borrowed(v) => {
if v == &*input {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should just check input.len() == v.len()? Comparing the whole string seems a bit unfortunate.

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

Successfully merging this pull request may close these issues.

3 participants