mirror of
https://github.com/codewhale-hq/Codewhale.git
synced 2026-11-07 17:09:13 -10:00
fix(execpolicy): an escaped quote outside quotes does not open a string
Outside quotes, a backslash now consumes a following `"`, `'` or `\`, the same pairing the double-quoted branch already applies. Other characters are left alone, so a Windows path such as `C:\;` still splits on the `;`.
This commit is contained in:
1 parent
b46f9a7703
commit
82a14ee2d1
2 files changed
+10
No files matched your search
@@ -2042,6 +2042,13 @@ fn split_command_segments(command: &str) -> Vec<String> {
|
||||
continue;
|
||||
}
|
||||
match ch {
|
||||
'\\' if chars
|
||||
.peek()
|
||||
.is_some_and(|next| matches!(next, '"' | '\'' | '\\')) =>
|
||||
{
|
||||
current.push(ch);
|
||||
current.push(chars.next().unwrap());
|
||||
}
|
||||
'\'' | '"' => {
|
||||
quote = Some(ch);
|
||||
current.push(ch);
|
||||
@@ -3040,6 +3047,8 @@ mod tests {
|
||||
"echo x & rm -rf /etc",
|
||||
"echo x&rm -rf /etc",
|
||||
r#"printf "\\";rm -rf /etc"#,
|
||||
r#"echo \";rm -rf /etc"#,
|
||||
r#"echo \';rm -rf /etc"#,
|
||||
"npm test 2>&1&rm -rf /etc",
|
||||
"curl https://example.com & rm -rf /etc",
|
||||
] {
|
||||
|
||||
@@ -2764,6 +2764,7 @@ mod tests {
|
||||
"dd if=/dev/zero of=\"/dev/sda\"",
|
||||
"cat junk | dd of=/dev/sda",
|
||||
"timeout 30 mkfs /dev/sda1",
|
||||
r#"echo \";mkfs.ext4 /dev/sda1"#,
|
||||
] {
|
||||
let ctx = ctx_for(
|
||||
"exec_shell",
|
||||
|
||||
Reference in new issue
Block a user