From d7165108cb3106f4b4bb75db57e66b34b1d3ec94 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 25 Jun 2020 10:47:54 +0200 Subject: [PATCH] api/router: percent decode the components of the uri those can contain percent encoded values, so we have to decode them before lookin up the path this is especially important for the 'MatchAll' branch when the parameter can contain some reserved characters Signed-off-by: Dominik Csapak --- proxmox/Cargo.toml | 1 + proxmox/src/api/router.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/proxmox/Cargo.toml b/proxmox/Cargo.toml index 7d5c06eb..0667de92 100644 --- a/proxmox/Cargo.toml +++ b/proxmox/Cargo.toml @@ -36,6 +36,7 @@ bytes = "0.5" futures = "0.3" http = "0.2" hyper = { version = "0.13", optional = true } +percent-encoding = "2.1" rustyline = "6" serde_derive = "1.0" textwrap = "0.11" diff --git a/proxmox/src/api/router.rs b/proxmox/src/api/router.rs index 11f5e003..5c0eeb01 100644 --- a/proxmox/src/api/router.rs +++ b/proxmox/src/api/router.rs @@ -8,6 +8,7 @@ use http::request::Parts; use http::{Method, Response}; use hyper::Body; use serde_json::Value; +use percent_encoding::percent_decode_str; use crate::api::schema::{self, ObjectSchema, Schema}; use crate::api::RpcEnvironment; @@ -323,10 +324,15 @@ impl Router { let (dir, remaining) = (components[0], &components[1..]); + let dir = match percent_decode_str(dir).decode_utf8() { + Ok(dir) => dir.to_string(), + Err(_) => return None, + }; + match self.subroute { None => {} Some(SubRoute::Map(dirmap)) => { - if let Ok(ind) = dirmap.binary_search_by_key(&dir, |(name, _)| name) { + if let Ok(ind) = dirmap.binary_search_by_key(&dir.as_str(), |(name, _)| name) { let (_name, router) = dirmap[ind]; //println!("FOUND SUBDIR {}", dir); return router.find_route(remaining, uri_param); @@ -334,7 +340,7 @@ impl Router { } Some(SubRoute::MatchAll { router, param_name }) => { //println!("URI PARAM {} = {}", param_name, dir); // fixme: store somewhere - uri_param.insert(param_name.to_owned(), dir.into()); + uri_param.insert(param_name.to_owned(), dir); return router.find_route(remaining, uri_param); } }