Skip to content
Merged
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
48 changes: 42 additions & 6 deletions crates/bashkit/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ impl<'a> Lexer<'a> {
'\n' => {
self.advance();
}
'"' | '\\' | '$' | '`' => {
'$' => {
// Use NUL sentinel so parse_word() treats this
// as a literal '$' rather than a variable expansion.
word.push('\x00');
word.push('$');
self.advance();
}
'"' | '\\' | '`' => {
word.push(next);
self.advance();
}
Expand Down Expand Up @@ -512,7 +519,14 @@ impl<'a> Lexer<'a> {
// \<newline> is line continuation: discard both
self.advance();
}
'"' | '\\' | '$' | '`' => {
'$' => {
// Use NUL sentinel so parse_word() treats this
// as a literal '$' rather than a variable expansion.
word.push('\x00');
word.push('$');
self.advance();
}
'"' | '\\' | '`' => {
word.push(next);
self.advance();
}
Expand Down Expand Up @@ -568,7 +582,12 @@ impl<'a> Lexer<'a> {
'\n' => {
self.advance();
}
'"' | '\\' | '$' | '`' => {
'$' => {
word.push('\x00');
word.push('$');
self.advance();
}
'"' | '\\' | '`' => {
word.push(next);
self.advance();
}
Expand Down Expand Up @@ -937,7 +956,12 @@ impl<'a> Lexer<'a> {
self.advance();
if let Some(next) = self.peek_char() {
match next {
'"' | '\\' | '$' | '`' => {
'$' => {
content.push('\x00');
content.push('$');
self.advance();
}
'"' | '\\' | '`' => {
content.push(next);
self.advance();
}
Expand Down Expand Up @@ -1108,7 +1132,14 @@ impl<'a> Lexer<'a> {
// \<newline> is line continuation: discard both
self.advance();
}
'"' | '\\' | '$' | '`' => {
'$' => {
// Use NUL sentinel so parse_word() treats this
// as a literal '$' rather than a variable expansion.
content.push('\x00');
content.push('$');
self.advance();
}
'"' | '\\' | '`' => {
content.push(next);
self.advance();
}
Expand Down Expand Up @@ -1332,7 +1363,12 @@ impl<'a> Lexer<'a> {
self.advance();
if let Some(esc) = self.peek_char() {
match esc {
'"' | '\\' | '$' | '`' => {
'$' => {
content.push('\x00');
content.push('$');
self.advance();
}
'"' | '\\' | '`' => {
content.push(esc);
self.advance();
}
Expand Down
7 changes: 6 additions & 1 deletion crates/bashkit/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,12 @@ impl<'a> Parser<'a> {
let mut current = String::new();

while let Some(ch) = chars.next() {
if ch == '$' {
if ch == '\x00' {
// NUL sentinel from lexer: next char is a literal (escaped in source).
if let Some(literal_ch) = chars.next() {
current.push(literal_ch);
}
} else if ch == '$' {
// Flush current literal
if !current.is_empty() {
parts.push(WordPart::Literal(std::mem::take(&mut current)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,11 +1370,10 @@ say "hello"
### end

### escaped_dollar
### bash_diff: echo "\$HOME" — bashkit expands the variable instead of treating \$ as literal (#668)
# Escaped dollar sign — bash: "$HOME", bashkit: "/home/sandbox"
# Escaped dollar sign — bash treats \$ in double quotes as literal $
echo "\$HOME"
### expect
/home/sandbox
$HOME
### end

### escaped_backtick
Expand Down
Loading