From be9ebd9e18708527ec105551d0beac01f888ec42 Mon Sep 17 00:00:00 2001 From: ahkrr <44893716+ahkrr@users.noreply.github.com> Date: Mon, 31 May 2021 17:22:46 +0200 Subject: [PATCH] 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 --- crates/nu-cli/src/shell/completer.rs | 2 +- crates/nu_plugin_post/Cargo.toml | 3 ++- crates/nu_plugin_post/src/post.rs | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/nu-cli/src/shell/completer.rs b/crates/nu-cli/src/shell/completer.rs index 517d4a4ef3..085df33df5 100644 --- a/crates/nu-cli/src/shell/completer.rs +++ b/crates/nu-cli/src/shell/completer.rs @@ -138,7 +138,7 @@ fn requote(orig_value: String) -> String { let mut quotes = vec!['"', '\'', '`']; let mut should_quote = false; for c in value.chars() { - if c.is_whitespace() { + if c.is_whitespace() || c == '#' { should_quote = true; } else if let Some(index) = quotes.iter().position(|q| *q == c) { should_quote = true; diff --git a/crates/nu_plugin_post/Cargo.toml b/crates/nu_plugin_post/Cargo.toml index 6ebc38d7d7..9aa63e701b 100644 --- a/crates/nu_plugin_post/Cargo.toml +++ b/crates/nu_plugin_post/Cargo.toml @@ -12,13 +12,14 @@ doctest = false [dependencies] base64 = "0.13.0" futures = { version = "0.3.5", features = ["compat", "io-compat"] } +mime = "0.3.16" nu-errors = { path = "../nu-errors", version = "0.31.1" } nu-plugin = { path = "../nu-plugin", version = "0.31.1" } nu-protocol = { path = "../nu-protocol", version = "0.31.1" } nu-source = { path = "../nu-source", version = "0.31.1" } num-traits = "0.2.12" serde_json = "1.0.57" -surf = "1.0.3" +surf = "2.2.0" url = "2.1.1" [features] diff --git a/crates/nu_plugin_post/src/post.rs b/crates/nu_plugin_post/src/post.rs index f065769e8f..ad9c60a27c 100644 --- a/crates/nu_plugin_post/src/post.rs +++ b/crates/nu_plugin_post/src/post.rs @@ -9,7 +9,6 @@ use nu_source::{AnchorLocation, Tag, TaggedItem}; use num_traits::cast::ToPrimitive; use std::path::PathBuf; use std::str::FromStr; -use surf::mime; #[derive(Clone)] pub enum HeaderKind { @@ -133,15 +132,15 @@ pub async fn post( 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 { - s = s.set_header("Authorization", format!("Basic {}", login)); + s = s.header("Authorization", format!("Basic {}", login)); } for h in headers { s = match h { - HeaderKind::ContentType(ct) => s.set_header("Content-Type", ct), - HeaderKind::ContentLength(cl) => s.set_header("Content-Length", cl), + HeaderKind::ContentType(ct) => s.header("Content-Type", ct), + HeaderKind::ContentLength(cl) => s.header("Content-Length", cl), }; } s.await @@ -150,9 +149,9 @@ pub async fn post( 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 { - s = s.set_header("Authorization", format!("Basic {}", login)); + s = s.header("Authorization", format!("Basic {}", login)); } s.await } @@ -160,10 +159,10 @@ pub async fn post( match value_to_json_value(&value.clone().into_untagged_value()) { Ok(json_value) => match serde_json::to_string(&json_value) { 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 { - s = s.set_header("Authorization", format!("Basic {}", login)); + s = s.header("Authorization", format!("Basic {}", login)); } s.await } @@ -186,9 +185,9 @@ pub async fn post( } }; match response { - Ok(mut r) => match r.headers().get("content-type") { + Ok(mut r) => match r.header("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( format!("Unknown MIME type: {}", content_type), "unknown MIME type",