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

Only strip spaces from opaque path when both query and fragment are null #842

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,12 +1552,12 @@ impl Url {
parser::Input::trim_tab_and_newlines(input, vfn),
)
});
self.restore_already_parsed_fragment(fragment);
} else {
self.query_start = None;
self.restore_already_parsed_fragment(fragment);
self.strip_trailing_spaces_from_opaque_path();
Comment on lines +1558 to 1559
Copy link
Author

Choose a reason for hiding this comment

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

Stripping spaces should only happen when the fragment is null, so the fragment should be restored first.

}

self.restore_already_parsed_fragment(fragment);
}

/// Manipulate this URL’s query string, viewed as a sequence of name/value pairs
Expand Down
9 changes: 9 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ fn test_strip_trailing_spaces_from_opaque_path() {
let mut url: Url = "data:space #hash".parse().unwrap();
url.set_fragment(None);
assert_eq!(url.as_str(), "data:space");

// Strip spaces only when both query and fragment are null.
let mut url: Url = "data:space ?query#hash".parse().unwrap();
url.set_query(None);
assert_eq!(url.as_str(), "data:space #hash");

let mut url: Url = "data:space ?query#hash".parse().unwrap();
url.set_fragment(None);
assert_eq!(url.as_str(), "data:space ?query");
}

#[test]
Expand Down