mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix: fetch bad URL will not panic (#8884)
This commit is contained in:
parent
bfe1b05381
commit
c1fdb30394
4 changed files with 51 additions and 10 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -771,6 +771,16 @@ version = "1.0.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "from_variant"
|
||||
version = "0.1.2"
|
||||
|
@ -3019,10 +3029,11 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
|||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.1.1"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
|
||||
checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
|
|
|
@ -27,12 +27,37 @@ unitTest(
|
|||
async (): Promise<void> => {
|
||||
await fetch("http://localhost:4000");
|
||||
},
|
||||
Deno.errors.Http,
|
||||
TypeError,
|
||||
"error trying to connect",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function fetchDnsError(): Promise<void> {
|
||||
await assertThrowsAsync(
|
||||
async (): Promise<void> => {
|
||||
await fetch("http://nil/");
|
||||
},
|
||||
TypeError,
|
||||
"error trying to connect",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function fetchInvalidUriError(): Promise<void> {
|
||||
await assertThrowsAsync(
|
||||
async (): Promise<void> => {
|
||||
await fetch("http://<invalid>/");
|
||||
},
|
||||
URIError,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
unitTest({ perms: { net: true } }, async function fetchJsonSuccess(): Promise<
|
||||
void
|
||||
> {
|
||||
|
@ -199,9 +224,12 @@ unitTest({ perms: { net: true } }, async function responseClone(): Promise<
|
|||
unitTest({ perms: { net: true } }, async function fetchEmptyInvalid(): Promise<
|
||||
void
|
||||
> {
|
||||
await assertThrowsAsync(async () => {
|
||||
await assertThrowsAsync(
|
||||
async () => {
|
||||
await fetch("");
|
||||
}, URIError);
|
||||
},
|
||||
URIError,
|
||||
);
|
||||
});
|
||||
|
||||
unitTest(
|
||||
|
|
|
@ -23,7 +23,7 @@ rusty_v8 = "0.14.0"
|
|||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
smallvec = "1.4.2"
|
||||
url = { version = "2.1.1", features = ["serde"] }
|
||||
url = { version = "2.2", features = ["serde"] }
|
||||
pin-project = "1.0.2"
|
||||
|
||||
[[example]]
|
||||
|
|
|
@ -8,7 +8,6 @@ use deno_core::error::AnyError;
|
|||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::url;
|
||||
use deno_core::url::Url;
|
||||
use deno_core::AsyncRefCell;
|
||||
use deno_core::BufVec;
|
||||
|
@ -126,7 +125,7 @@ where
|
|||
None => Method::GET,
|
||||
};
|
||||
|
||||
let url_ = url::Url::parse(&url)?;
|
||||
let url_ = Url::parse(&url)?;
|
||||
|
||||
// Check scheme before asking for net permission
|
||||
let scheme = url_.scheme();
|
||||
|
@ -155,7 +154,10 @@ where
|
|||
}
|
||||
//debug!("Before fetch {}", url);
|
||||
|
||||
let res = request.send().await?;
|
||||
let res = match request.send().await {
|
||||
Ok(res) => res,
|
||||
Err(e) => return Err(type_error(e.to_string())),
|
||||
};
|
||||
|
||||
//debug!("Fetch response {}", url);
|
||||
let status = res.status();
|
||||
|
|
Loading…
Reference in a new issue