mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 15:44:36 +00:00
fix(cli/flags): don't panic on invalid location scheme (#9202)
This commit is contained in:
parent
25830a1067
commit
452df2f23a
1 changed files with 14 additions and 3 deletions
15
cli/flags.rs
15
cli/flags.rs
|
@ -1475,11 +1475,11 @@ fn location_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
return Err("Failed to parse URL".to_string());
|
return Err("Failed to parse URL".to_string());
|
||||||
}
|
}
|
||||||
let mut url = url.unwrap();
|
let mut url = url.unwrap();
|
||||||
url.set_username("").unwrap();
|
|
||||||
url.set_password(None).unwrap();
|
|
||||||
if !["http", "https"].contains(&url.scheme()) {
|
if !["http", "https"].contains(&url.scheme()) {
|
||||||
return Err("Expected protocol \"http\" or \"https\"".to_string());
|
return Err("Expected protocol \"http\" or \"https\"".to_string());
|
||||||
}
|
}
|
||||||
|
url.set_username("").unwrap();
|
||||||
|
url.set_password(None).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.help("Value of 'globalThis.location' used by some web APIs")
|
.help("Value of 'globalThis.location' used by some web APIs")
|
||||||
|
@ -3411,4 +3411,15 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn location_with_bad_scheme() {
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let r = flags_from_vec(svec!["deno", "run", "--location", "foo:", "mod.ts"]);
|
||||||
|
assert!(r.is_err());
|
||||||
|
assert!(r
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string()
|
||||||
|
.contains("Expected protocol \"http\" or \"https\""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue