mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
Prevent panic for wget and http_client on invalid non http URL input
This commit is contained in:
parent
cf2411dbd8
commit
642727aae9
|
@ -17,6 +17,7 @@
|
|||
* New concat command.
|
||||
* Improve wget input parsing.
|
||||
* Modify full named commands.
|
||||
* Prevent panic for wget and http_client on invalid non http URL input.
|
||||
|
||||
### v0.1.8 (2020-01-24)
|
||||
|
||||
|
|
|
@ -153,12 +153,17 @@ impl Command for CommandImpl {
|
|||
let len = arguments.len() - 1;
|
||||
let url = arguments[len].to_string();
|
||||
|
||||
let url_lowercase = url.to_lowercase();
|
||||
if !url_lowercase.starts_with("http://") && !url_lowercase.starts_with("https://") {
|
||||
CommandResult::Error(format!("Invalid URL: {} provided.", &url).to_string())
|
||||
} else {
|
||||
match parse_options(&arguments[0..len].to_vec()) {
|
||||
Ok(options) => do_request(url, options),
|
||||
Err(error) => CommandResult::Error(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||
|
|
|
@ -51,3 +51,8 @@ fn run_post() {
|
|||
CommandValidation::Contains("out".to_string(), "success".to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_invalid_url() {
|
||||
test::run_script_and_error(vec![create("")], "out = http_client invalid_url", "out");
|
||||
}
|
||||
|
|
|
@ -28,3 +28,17 @@ function test_post
|
|||
|
||||
assert ${found}
|
||||
end
|
||||
|
||||
function test_invalid_url
|
||||
error = get_last_error
|
||||
empty = is_empty ${error}
|
||||
assert ${empty}
|
||||
|
||||
response = http_client invalid_url
|
||||
|
||||
error = get_last_error
|
||||
empty = is_empty ${error}
|
||||
assert_false ${empty}
|
||||
|
||||
assert_false ${response}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue