fix: filename quoting # and update and unify surf dependency (#3524)

* fix: filenames with '#' don't get quoted #3496

* updating and unifying dependency surf

* adding hyper-client

Co-authored-by: ahkrr <alexhk@protonmail.com>
This commit is contained in:
ahkrr 2021-05-31 17:22:46 +02:00 committed by GitHub
parent 01f1208ad1
commit be9ebd9e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -138,7 +138,7 @@ fn requote(orig_value: String) -> String {
let mut quotes = vec!['"', '\'', '`']; let mut quotes = vec!['"', '\'', '`'];
let mut should_quote = false; let mut should_quote = false;
for c in value.chars() { for c in value.chars() {
if c.is_whitespace() { if c.is_whitespace() || c == '#' {
should_quote = true; should_quote = true;
} else if let Some(index) = quotes.iter().position(|q| *q == c) { } else if let Some(index) = quotes.iter().position(|q| *q == c) {
should_quote = true; should_quote = true;

View File

@ -12,13 +12,14 @@ doctest = false
[dependencies] [dependencies]
base64 = "0.13.0" base64 = "0.13.0"
futures = { version = "0.3.5", features = ["compat", "io-compat"] } futures = { version = "0.3.5", features = ["compat", "io-compat"] }
mime = "0.3.16"
nu-errors = { path = "../nu-errors", version = "0.31.1" } nu-errors = { path = "../nu-errors", version = "0.31.1" }
nu-plugin = { path = "../nu-plugin", version = "0.31.1" } nu-plugin = { path = "../nu-plugin", version = "0.31.1" }
nu-protocol = { path = "../nu-protocol", version = "0.31.1" } nu-protocol = { path = "../nu-protocol", version = "0.31.1" }
nu-source = { path = "../nu-source", version = "0.31.1" } nu-source = { path = "../nu-source", version = "0.31.1" }
num-traits = "0.2.12" num-traits = "0.2.12"
serde_json = "1.0.57" serde_json = "1.0.57"
surf = "1.0.3" surf = "2.2.0"
url = "2.1.1" url = "2.1.1"
[features] [features]

View File

@ -9,7 +9,6 @@ use nu_source::{AnchorLocation, Tag, TaggedItem};
use num_traits::cast::ToPrimitive; use num_traits::cast::ToPrimitive;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use surf::mime;
#[derive(Clone)] #[derive(Clone)]
pub enum HeaderKind { pub enum HeaderKind {
@ -133,15 +132,15 @@ pub async fn post(
value: UntaggedValue::Primitive(Primitive::String(body_str)), value: UntaggedValue::Primitive(Primitive::String(body_str)),
.. ..
} => { } => {
let mut s = surf::post(location).body_string(body_str.to_string()); let mut s = surf::post(location).body(body_str.to_string());
if let Some(login) = login { if let Some(login) = login {
s = s.set_header("Authorization", format!("Basic {}", login)); s = s.header("Authorization", format!("Basic {}", login));
} }
for h in headers { for h in headers {
s = match h { s = match h {
HeaderKind::ContentType(ct) => s.set_header("Content-Type", ct), HeaderKind::ContentType(ct) => s.header("Content-Type", ct),
HeaderKind::ContentLength(cl) => s.set_header("Content-Length", cl), HeaderKind::ContentLength(cl) => s.header("Content-Length", cl),
}; };
} }
s.await s.await
@ -150,9 +149,9 @@ pub async fn post(
value: UntaggedValue::Primitive(Primitive::Binary(b)), value: UntaggedValue::Primitive(Primitive::Binary(b)),
.. ..
} => { } => {
let mut s = surf::post(location).body_bytes(b); let mut s = surf::post(location).body(&b[..]);
if let Some(login) = login { if let Some(login) = login {
s = s.set_header("Authorization", format!("Basic {}", login)); s = s.header("Authorization", format!("Basic {}", login));
} }
s.await s.await
} }
@ -160,10 +159,10 @@ pub async fn post(
match value_to_json_value(&value.clone().into_untagged_value()) { match value_to_json_value(&value.clone().into_untagged_value()) {
Ok(json_value) => match serde_json::to_string(&json_value) { Ok(json_value) => match serde_json::to_string(&json_value) {
Ok(result_string) => { Ok(result_string) => {
let mut s = surf::post(location).body_string(result_string); let mut s = surf::post(location).body(result_string);
if let Some(login) = login { if let Some(login) = login {
s = s.set_header("Authorization", format!("Basic {}", login)); s = s.header("Authorization", format!("Basic {}", login));
} }
s.await s.await
} }
@ -186,9 +185,9 @@ pub async fn post(
} }
}; };
match response { match response {
Ok(mut r) => match r.headers().get("content-type") { Ok(mut r) => match r.header("content-type") {
Some(content_type) => { Some(content_type) => {
let content_type = Mime::from_str(content_type).map_err(|_| { let content_type = Mime::from_str(content_type.as_str()).map_err(|_| {
ShellError::labeled_error( ShellError::labeled_error(
format!("Unknown MIME type: {}", content_type), format!("Unknown MIME type: {}", content_type),
"unknown MIME type", "unknown MIME type",