Skip to content

Commit 9d23a7d

Browse files
Fix percent encoded parameters (#1324)
Change: percent-decode
1 parent ade86d2 commit 9d23a7d

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

josh-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ toml = { workspace = true }
3636
tracing = { workspace = true }
3737
gix = { workspace = true }
3838
juniper = { workspace = true }
39+
form_urlencoded = "1.2.1"
3940

4041
[dependencies.chrono]
4142
default-features = false

josh-core/src/query.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@ pub fn render(
124124
query_and_params: &str,
125125
split_odb: bool,
126126
) -> JoshResult<Option<(String, std::collections::BTreeMap<String, String>)>> {
127-
let mut parameters = query_and_params.split('&');
128-
let query = parameters
129-
.next()
130-
.ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?;
131-
let mut split = query.splitn(2, '=');
132-
let cmd = split
133-
.next()
134-
.ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?;
135-
let path = split
136-
.next()
137-
.ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?;
127+
let params = form_urlencoded::parse(&query_and_params.as_bytes())
128+
.map(|(x, y)| (x.to_string(), y.to_string()))
129+
.collect::<std::collections::BTreeMap<_, _>>();
130+
let (cmd, path) = if let Some(path) = params.get("get") {
131+
("get", path)
132+
} else if let Some(path) = params.get("graphql") {
133+
("graphql", path)
134+
} else if let Some(path) = params.get("render") {
135+
("render", path)
136+
} else {
137+
return Err(josh_error("no command"));
138+
};
138139

139140
let tree = transaction.repo().find_commit(commit_id)?.tree()?;
140141

@@ -146,18 +147,6 @@ pub fn render(
146147
}
147148
);
148149

149-
let mut params = std::collections::BTreeMap::new();
150-
for p in parameters {
151-
let mut split = p.splitn(2, '=');
152-
let name = split
153-
.next()
154-
.ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?;
155-
let value = split
156-
.next()
157-
.ok_or_else(|| josh_error(&format!("invalid query {:?}", query_and_params)))?;
158-
params.insert(name.to_string(), value.to_string());
159-
}
160-
161150
let template = if let Ok(blob) = obj.peel_to_blob() {
162151
let file = std::str::from_utf8(blob.content())?;
163152
if cmd == "get" {

tests/filter/graphql_hbs.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,10 @@
306306
]
307307
}
308308
} (no-eol)
309-
$ josh-filter -q "render=sub1/tmpl_file&tmpl_param1=tmpl_param_value1&tmpl_p2=val2"
309+
310+
$ josh-filter -q "render=sub1%2Ftmpl_file&tmpl_param1=tmpl_param_value1&tmpl_p2=val%252"
310311
tmpl_param1: tmpl_param_value1
311-
tmpl_p2: val2
312+
tmpl_p2: val%2
312313
ID: a00263b0ee48ce1badf88d178a1e4fc27546aad0
313314
Summary: add templ_file
314315
From TOML: my_value

0 commit comments

Comments
 (0)