From 506150efaeb5176836301f939ff2c309e43b1983 Mon Sep 17 00:00:00 2001 From: Matthew Wootten Date: Mon, 28 Aug 2023 15:43:19 -0400 Subject: [PATCH] Fix #132 by adjusting querystring processing The backend decodes querystrings with the qstring crate. However, that decodes both a plus sign and a URL-encoded plus sign to exactly the same thing, erasing the distinction between plus signs and spaces (see algesten/qstring#3). This patch instead uses the underlying url crate, which handles plus signs correctly. This fix should be combined with #138, which fixes the frontend piece; however, merging just this one would correct the saving in the backend. --- Cargo.lock | 10 ---------- Cargo.toml | 1 - src/form_parameters.rs | 7 ++----- src/main.rs | 7 ++++--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb03875..1a9c600 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1634,7 +1634,6 @@ dependencies = [ "lazy_static", "mysql_async", "percent-encoding", - "qstring", "rand", "rayon", "regex", @@ -1761,15 +1760,6 @@ dependencies = [ "psl-types", ] -[[package]] -name = "qstring" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" -dependencies = [ - "percent-encoding", -] - [[package]] name = "quote" version = "1.0.28" diff --git a/Cargo.toml b/Cargo.toml index 88bcd03..ced1902 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ wikibase = { git = "https://gitlab.com/tobias47n9e/wikibase_rs" } tokio = { version = "^1", features = ["macros","fs","sync"] } tokio-util = "*" hyper = { version = "^0.14", features = ["full"] } -qstring = "*" futures = "*" [profile.release] diff --git a/src/form_parameters.rs b/src/form_parameters.rs index e8ac2c8..34caa22 100644 --- a/src/form_parameters.rs +++ b/src/form_parameters.rs @@ -27,12 +27,9 @@ impl FormParameters { Self { ..Default::default() } } - pub fn new_from_pairs(parameter_pairs: Vec<(&str, &str)>) -> Self { + pub fn new_from_pairs(parameter_pairs: HashMap) -> Self { let mut ret = Self::new(); - ret.params = parameter_pairs - .iter() - .map(|(k, v)| (k.to_string(), v.to_string().replace("+", " "))) - .collect(); + ret.params = parameter_pairs; ret.ns = Self::ns_from_params(&ret.params); ret.legacy_parameters(); ret diff --git a/src/main.rs b/src/main.rs index 75d2025..790ef92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ pub mod wdfist; use tokio::fs::File as TokioFile; use tokio_util::codec::{BytesCodec, FramedRead}; -use qstring::QString; +use url::form_urlencoded; use crate::form_parameters::FormParameters; use app_state::AppState; use platform::{MyResponse, Platform, ContentType}; @@ -35,8 +35,9 @@ use hyper::service::{make_service_fn, service_fn}; static NOTFOUND: &[u8] = b"Not Found"; async fn process_form(parameters:&str, state: Arc) -> MyResponse { - let parameter_pairs = QString::from(parameters) ; - let parameter_pairs = parameter_pairs.to_pairs() ; + let parameter_pairs = form_urlencoded::parse(parameters.as_bytes()) + .map(|(k, v)| (k.into_owned(), v.into_owned())) + .collect(); let mut form_parameters = FormParameters::new_from_pairs ( parameter_pairs ) ; // Restart command?