summaryrefslogtreecommitdiffhomepage
path: root/talpid-core
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-10-20 09:50:40 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-10-20 09:50:40 +0200
commit8d596d694882baed3b891864d25768c42b502e79 (patch)
treefe96da4d2e159815835d10c002dfb66bcd64db11 /talpid-core
parent9a7f29d3dc55133b0bf2b82001310e61b0d3fef5 (diff)
parent25644538dee35ab40653a8f63cdf8425aeb35e57 (diff)
downloadmullvadvpn-8d596d694882baed3b891864d25768c42b502e79.tar.xz
mullvadvpn-8d596d694882baed3b891864d25768c42b502e79.zip
Merge branch 'nicer-openvpn-expression-fmt'
Diffstat (limited to 'talpid-core')
-rw-r--r--talpid-core/Cargo.toml1
-rw-r--r--talpid-core/src/lib.rs1
-rw-r--r--talpid-core/src/process/openvpn.rs21
3 files changed, 7 insertions, 16 deletions
diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml
index a811c911a4..1c04bdacef 100644
--- a/talpid-core/Cargo.toml
+++ b/talpid-core/Cargo.toml
@@ -13,6 +13,7 @@ jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc", tag = "v7.1.1"
lazy_static = "0.2"
log = "0.3"
uuid = { version = "0.5", features = ["v4"] }
+shell-escape = "0.1"
openvpn-plugin = { version = "0.3", features = ["serde"] }
talpid-ipc = { path = "../talpid-ipc" }
diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs
index da6c49c580..1af5587def 100644
--- a/talpid-core/src/lib.rs
+++ b/talpid-core/src/lib.rs
@@ -22,6 +22,7 @@ extern crate error_chain;
extern crate jsonrpc_core;
#[macro_use]
extern crate jsonrpc_macros;
+extern crate shell_escape;
extern crate uuid;
extern crate openvpn_plugin;
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs
index 0c534f63b9..ec0487c4bd 100644
--- a/talpid-core/src/process/openvpn.rs
+++ b/talpid-core/src/process/openvpn.rs
@@ -4,6 +4,7 @@ use std::ffi::{OsStr, OsString};
use std::fmt;
use std::path::{Path, PathBuf};
+use shell_escape;
use talpid_types::net;
static BASE_ARGUMENTS: &[&[&str]] = &[
@@ -189,27 +190,15 @@ impl fmt::Display for OpenVpnCommand {
/// Format the program and arguments of an `OpenVpnCommand` for display. Any non-utf8 data
/// is lossily converted using the utf8 replacement character.
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- fmt.write_str(&self.openvpn_bin.to_string_lossy())?;
- for arg in self.get_arguments().iter().map(|arg| arg.to_string_lossy()) {
- write_argument(fmt, &arg)?;
+ fmt.write_str(&shell_escape::escape(self.openvpn_bin.to_string_lossy()))?;
+ for arg in &self.get_arguments() {
+ fmt.write_str(" ")?;
+ fmt.write_str(&shell_escape::escape(arg.to_string_lossy()))?;
}
Ok(())
}
}
-fn write_argument(fmt: &mut fmt::Formatter, arg: &str) -> fmt::Result {
- fmt.write_str(" ")?;
- let quote = arg.contains(char::is_whitespace);
- if quote {
- fmt.write_str("\"")?;
- }
- fmt.write_str(arg)?;
- if quote {
- fmt.write_str("\"")?;
- }
- Ok(())
-}
-
#[cfg(test)]
mod tests {