Skip to content

Commit

Permalink
Fix escaping issues in shell outs (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 16, 2020
1 parent 4853a67 commit 17b9987
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.5.1"
version = "2.5.2"
authors = ["Denis Isidoro <[email protected]>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
Expand Down
18 changes: 14 additions & 4 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exst() {
type "$1" &>/dev/null
}
_paste() {
_copy() {
if exst pbcopy; then
pbcopy
elif exst xclip; then
Expand All @@ -18,12 +18,22 @@ _paste() {
else
exit 55
fi
}
"#;
}"#;

Command::new("bash")
.arg("-c")
.arg(format!(r#"{} echo "{}" | _paste"#, cmd, text).as_str())
.arg(
format!(
r#"{}
read -r -d '' x <<'EOF'
{}
EOF
echo -n "$x" | _copy"#,
cmd, text
)
.as_str(),
)
.spawn()
.map_err(|e| BashSpawnError::new(cmd, e))?;

Expand Down
6 changes: 3 additions & 3 deletions src/flows/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub fn main(func: String, args: Vec<String>) -> Result<(), Error> {
.next()
.ok_or_else(|| anyhow!("No URL specified"))?;
let cmd = format!(
r#"url="$(echo "{}" | tr ' ' '+')"; (xdg-open "$url" 2> /dev/null || open "$url" 2> /dev/null) &disown"#,
url
r#"url="{}"; (xdg-open "$url" 2> /dev/null || open "$url" 2> /dev/null) &disown"#,
url.replace('"', "").replace('\'', "").replace(' ', "+")
);
Command::new("bash")
.arg("-c")
Expand All @@ -23,7 +23,7 @@ pub fn main(func: String, args: Vec<String>) -> Result<(), Error> {
}

"welcome" => handler::handle_config(option::config_from_iter(
"navi --path /tmp/irrelevant".split(' ').collect(),
"navi --path /tmp/navi/irrelevant".split(' ').collect(),
)),

_ => Err(anyhow!("Unrecognized function")),
Expand Down
12 changes: 7 additions & 5 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use anyhow::{Context, Error};
use std::process::Command;

pub fn shallow_clone(uri: &str, target: &str) -> Result<(), Error> {
let cmd = format!(r#"git clone "{}" "{}" --depth 1"#, uri, target);
Command::new("bash")
.arg("-c")
.arg(&cmd[..])
Command::new("git")
.arg("clone")
.arg(uri)
.arg(target)
.arg("--depth")
.arg("1")
.spawn()
.map_err(|e| BashSpawnError::new(&cmd[..], e))?
.map_err(|e| BashSpawnError::new("git clone", e))?
.wait()
.context("Unable to git clone")?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ for i in $(_get_tests "$filter"); do
test::run "$query" _navi_test "$query" "$expected"
done

test::finish
test::finish

0 comments on commit 17b9987

Please sign in to comment.