Skip to content
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
17 changes: 2 additions & 15 deletions crates/bashkit/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,6 @@ impl<'a> Lexer<'a> {
self.advance(); // consume opening "
let mut content = String::new();
let mut closed = false;
let mut has_quoted_expansion = false;

while let Some(ch) = self.peek_char() {
match ch {
'"' => {
Expand Down Expand Up @@ -1267,13 +1265,6 @@ impl<'a> Lexer<'a> {
'$' => {
content.push('$');
self.advance();
if self.peek_char().is_some_and(|nc| {
nc.is_ascii_alphanumeric()
|| nc == '_'
|| matches!(nc, '{' | '(' | '?' | '#' | '@' | '*' | '!' | '$' | '-')
}) {
has_quoted_expansion = true;
}
if self.peek_char() == Some('(') {
// $(...) command substitution — track paren depth
content.push('(');
Expand All @@ -1291,7 +1282,6 @@ impl<'a> Lexer<'a> {
}
'`' => {
// Backtick command substitution inside double quotes
has_quoted_expansion = true;
self.advance(); // consume opening `
content.push_str("$(");
while let Some(c) = self.peek_char() {
Expand Down Expand Up @@ -1343,13 +1333,10 @@ impl<'a> Lexer<'a> {
let has_glob = content[before_len..]
.chars()
.any(|c| matches!(c, '*' | '?' | '['));
if has_quoted_expansion && has_glob {
if has_glob {
return Some(Token::QuotedGlobWord(content));
}
if has_quoted_expansion {
return Some(Token::QuotedWord(content));
}
return Some(Token::Word(content));
return Some(Token::QuotedWord(content));
Comment on lines +1336 to +1339
}

Some(Token::QuotedWord(content))
Expand Down
40 changes: 40 additions & 0 deletions crates/bashkit/tests/integration/blackbox_security_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,46 @@ mod parser_edge_cases_passing {
"Single-quoted heredoc expanded command substitution"
);
}

/// Any quoted byte in the delimiter disables heredoc body expansion.
#[tokio::test]
async fn heredoc_partially_quoted_delimiter_no_expansion() {
let mut bash = tight_bash();
let result = bash
.exec("cat <<\"EOF\"x\n$(echo INJECTED)\nEOFx\n")
.await
.unwrap();
assert_eq!(
result.stdout, "$(echo INJECTED)\n",
"partially quoted heredoc delimiter expanded command substitution"
);
}
}

mod finding_mixed_quoted_word_quote_metadata {
use super::*;

#[tokio::test]
async fn quoted_glob_metacharacter_with_unquoted_suffix_stays_literal() {
let mut bash = tight_bash();
let result = bash.exec(r#"echo "*"x"#).await.unwrap();

assert_eq!(
result.stdout, "*x\n",
"glob metacharacter from quoted segment was expanded"
);
}

Comment on lines +1337 to +1347
#[tokio::test]
async fn quoted_brace_expression_with_unquoted_suffix_stays_literal() {
let mut bash = tight_bash();
let result = bash.exec(r#"echo "{1..3}"x"#).await.unwrap();

assert_eq!(
result.stdout, "{1..3}x\n",
"brace expression from quoted segment was expanded"
);
}
}

mod state_isolation_passing {
Expand Down