Skip to content

Commit

Permalink
Fix percent encoded parameters
Browse files Browse the repository at this point in the history
Change: percent-decode
  • Loading branch information
christian-schilling committed Apr 8, 2024
1 parent ade86d2 commit 72e02ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions josh-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 12 additions & 23 deletions josh-core/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,18 @@ pub fn render(
query_and_params: &str,
split_odb: bool,
) -> JoshResult<Option<(String, std::collections::BTreeMap<String, String>)>> {
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::<std::collections::BTreeMap<_, _>>();
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()?;

Expand All @@ -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" {
Expand Down
5 changes: 3 additions & 2 deletions tests/filter/graphql_hbs.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72e02ca

Please sign in to comment.