diff options
Diffstat (limited to 'crates/shirabe-php-shim/src/process.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/process.rs | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/crates/shirabe-php-shim/src/process.rs b/crates/shirabe-php-shim/src/process.rs index 4615ff91..57d9b35a 100644 --- a/crates/shirabe-php-shim/src/process.rs +++ b/crates/shirabe-php-shim/src/process.rs @@ -1,5 +1,6 @@ use crate::{ChildPipe, PhpMixed, PhpResource, StreamBacking, StreamState}; use indexmap::IndexMap; +pub use shirabe_php_src::standard::exec::escapeshellcmd; pub const SIGINT: i64 = 2; pub const SIGTERM: i64 = 15; @@ -77,44 +78,6 @@ pub fn system(command: &str, result_code: Option<&mut i64>) -> Option<String> { Some(lines.last().cloned().unwrap_or_default()) } -// Port of PHP's escapeshellcmd (Unix branch). Shell metacharacters are backslash-escaped; quote -// characters are escaped only when unpaired, paired quotes being left intact. -pub fn escapeshellcmd(command: &str) -> String { - let bytes = command.as_bytes(); - let len = bytes.len(); - let mut out: Vec<u8> = Vec::with_capacity(len); - // Byte index of the matching closing quote while inside a paired quote run. - let mut paired: Option<usize> = None; - let mut x = 0; - while x < len { - let c = bytes[x]; - match c { - b'"' | b'\'' => { - if paired.is_none() { - if let Some(rel) = bytes[x + 1..].iter().position(|&b| b == c) { - paired = Some(x + 1 + rel); - } else { - out.push(b'\\'); - } - } else if paired == Some(x) { - paired = None; - } else { - out.push(b'\\'); - } - out.push(c); - } - b'#' | b'&' | b';' | b'`' | b'|' | b'*' | b'?' | b'~' | b'<' | b'>' | b'^' | b'(' - | b')' | b'[' | b']' | b'{' | b'}' | b'$' | b'\\' | 0x0A | 0xFF => { - out.push(b'\\'); - out.push(c); - } - _ => out.push(c), - } - x += 1; - } - String::from_utf8_lossy(&out).into_owned() -} - // Unix branch of PHP's escapeshellarg: wrap in single quotes, escaping embedded single quotes. pub fn escapeshellarg(arg: &str) -> String { let mut out = String::with_capacity(arg.len() + 2); |
