diff --git a/josh-core/Cargo.toml b/josh-core/Cargo.toml index a430f5f5..3021920a 100644 --- a/josh-core/Cargo.toml +++ b/josh-core/Cargo.toml @@ -36,6 +36,7 @@ toml = { workspace = true } tracing = { workspace = true } gix = { workspace = true } juniper = { workspace = true } +form_urlencoded = "1.2.1" [dependencies.chrono] default-features = false diff --git a/josh-core/src/query.rs b/josh-core/src/query.rs index 22c5b515..e8c79d11 100644 --- a/josh-core/src/query.rs +++ b/josh-core/src/query.rs @@ -124,17 +124,18 @@ pub fn render( query_and_params: &str, split_odb: bool, ) -> JoshResult)>> { - let mut parameters = query_and_params.split('&'); - let query = parameters - .next() - .ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?; - let mut split = query.splitn(2, '='); - let cmd = split - .next() - .ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?; - let path = split - .next() - .ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?; + let params = form_urlencoded::parse(&query_and_params.as_bytes()) + .map(|(x, y)| (x.to_string(), y.to_string())) + .collect::>(); + let (cmd, path) = if let Some(path) = params.get("get") { + ("get", path) + } else if let Some(path) = params.get("graphql") { + ("graphql", path) + } else if let Some(path) = params.get("render") { + ("render", path) + } else { + return Err(josh_error("no command")); + }; let tree = transaction.repo().find_commit(commit_id)?.tree()?; @@ -146,18 +147,6 @@ pub fn render( } ); - let mut params = std::collections::BTreeMap::new(); - for p in parameters { - let mut split = p.splitn(2, '='); - let name = split - .next() - .ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?; - let value = split - .next() - .ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?; - params.insert(name.to_string(), value.to_string()); - } - let template = if let Ok(blob) = obj.peel_to_blob() { let file = std::str::from_utf8(blob.content())?; if cmd == "get" { diff --git a/tests/filter/graphql_hbs.t b/tests/filter/graphql_hbs.t index 72abc5aa..fa5833d0 100644 --- a/tests/filter/graphql_hbs.t +++ b/tests/filter/graphql_hbs.t @@ -306,9 +306,10 @@ ] } } (no-eol) - $ josh-filter -q "render=sub1/tmpl_file&tmpl_param1=tmpl_param_value1&tmpl_p2=val2" + + $ josh-filter -q "render=sub1%2Ftmpl_file&tmpl_param1=tmpl_param_value1&tmpl_p2=val%252" tmpl_param1: tmpl_param_value1 - tmpl_p2: val2 + tmpl_p2: val%2 ID: a00263b0ee48ce1badf88d178a1e4fc27546aad0 Summary: add templ_file From TOML: my_value