Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to shlex. #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ All notable changes to this project will be documented in this file.
* `ShellWriter::with_prefix()` now accepts anything that implements
`std::fmt::Display` as the prefix rather than just `String`s.

### Miscellaneous

* Switched from [shell-words] to [shlex] for shell escaping since I’ve
contributed to that crate.

[shell-words]: https://crates.io/crates/shell-words
[shlex]: https://crates.io/crates/shlex

## Release 1.0.2 (2023-05-24)

* Update documentation to reflect that the minimum supported Rust version
Expand Down
8 changes: 4 additions & 4 deletions 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
Expand Up @@ -16,7 +16,7 @@ rust-version = "1.64"
[dependencies]
clap = { version = "4.0.16", features = ["derive"] }
git2 = { version = "0.17.0", default-features = false }
shell-words = "1.1.0"
shlex = "1.2.0"

[dev-dependencies]
assert_cmd = "2.0.7"
Expand Down
6 changes: 3 additions & 3 deletions src/shell_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ pub trait ShellVars {
///
/// ```rust
/// use git_status_vars::shell_quote;
/// assert_eq!(shell_quote("a $b `c`\nd"), "'a $b `c`\nd'");
/// assert_eq!(shell_quote("a $b `c`\nd"), "\"a \\$b \\`c\\`\nd\"");
/// ```
pub fn shell_quote<V: Display>(value: V) -> String {
shell_words::quote(&value.to_string()).into()
shlex::quote(&value.to_string()).into()
}

/// Format a value with [`Debug`] and quote it for safe shell insertion.
pub fn shell_quote_debug<V: Debug>(value: V) -> String {
shell_words::quote(&format!("{value:?}")).into()
shlex::quote(&format!("{value:?}")).into()
}
8 changes: 5 additions & 3 deletions tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ where
I: IntoIterator<Item = S>,
S: Into<OsString>,
{
let args: Vec<OsString> = args.into_iter().map(Into::into).collect();
let shell_args =
shell_words::join(args.iter().map(|arg| arg.to_string_lossy()));
let args: Vec<String> = args
.into_iter()
.map(|arg| arg.into().to_string_lossy().into_owned())
.collect();
let shell_args = shlex::join(args.iter().map(std::string::String::as_str));

println!("`git {shell_args}` in {:?}", root.join(repo));
let output = run_git(root, repo, args).run()?;
Expand Down
Loading