Skip to content

Commit

Permalink
Trim whitespaces only while setting scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
CYBAI committed Feb 27, 2023
1 parent 6ef3876 commit cbc1b50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion url/src/lib.rs
Expand Up @@ -2314,7 +2314,7 @@ impl Url {
#[allow(clippy::result_unit_err, clippy::suspicious_operation_groupings)]
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()> {
let mut parser = Parser::for_setter(String::new());
let remaining = parser.parse_scheme(parser::Input::new(scheme))?;
let remaining = parser.parse_scheme(parser::Input::trim_tab_and_newlines(scheme, None))?;
let new_scheme_type = SchemeType::from(&parser.serialization);
let old_scheme_type = SchemeType::from(self.scheme());
// If url’s scheme is a special scheme and buffer is not a special scheme, then return.
Expand Down
11 changes: 11 additions & 0 deletions url/tests/unit.rs
Expand Up @@ -147,6 +147,17 @@ fn new_path_windows_fun() {
}
}

#[test]
fn set_scheme_with_leading_or_trailing_c0_controls_should_result_in_noop() {
let mut url: Url = "http://test".parse().unwrap();

let controls = ["\u{0000}", "\u{000C}", "\u{000E}", "\u{0020}"];
for control in controls.iter() {
assert!(url.set_scheme(&format!("{}https", control)).is_err());
assert!(url.set_scheme(&format!("https{}", control)).is_err());
}
}

#[test]
fn new_directory_paths() {
if cfg!(unix) {
Expand Down

0 comments on commit cbc1b50

Please sign in to comment.