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
13 changes: 13 additions & 0 deletions crates/bashkit/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,19 @@ impl<'a> Lexer<'a> {
self.advance();
}
}
Some('$') => {
// Check for $'...' ANSI-C quoting in continuation
let mut lookahead = self.chars.clone();
lookahead.next(); // skip $
if lookahead.next() == Some('\'') {
self.advance(); // consume $
self.advance(); // consume opening '
content.push_str(&self.read_dollar_single_quoted_content());
} else {
content.push('$');
self.advance();
}
}
Some(ch) if self.is_word_char(ch) => {
content.push(ch);
self.advance();
Expand Down
57 changes: 57 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/quote.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,60 @@ echo 'say "hi"'
### expect
say "hi"
### end

### quote_ansi_c_concat_func_arg
# Issue #862: $'\n' concatenated in function argument position
show() { printf '%q\n' "$1"; }
show "a"$'\n'"b"
### expect
$'a\nb'
### end

### quote_ansi_c_tab_concat_func_arg
# $'\t' concatenated in function argument position
show() { printf '%q\n' "$1"; }
show "a"$'\t'"b"
### expect
$'a\tb'
### end

### quote_ansi_c_sole_arg
# $'\n' as sole function argument
show() { printf '%q\n' "$1"; }
show $'\n'
### expect
$'\n'
### end

### quote_ansi_c_at_start
# $'\n' at start of concatenation
show() { printf '%q\n' "$1"; }
show $'\n'"after"
### expect
$'\nafter'
### end

### quote_ansi_c_at_end
# $'\n' at end of concatenation
show() { printf '%q\n' "$1"; }
show "before"$'\n'
### expect
$'before\n'
### end

### quote_ansi_c_multiple_segments
# Multiple ANSI-C segments concatenated
show() { printf '%q\n' "$1"; }
show "a"$'\n'"b"$'\t'"c"
### expect
$'a\nb\tc'
### end

### quote_ansi_c_via_variable_baseline
# Baseline: ANSI-C via variable works
show() { printf '%q\n' "$1"; }
x="a"$'\n'"b"
show "${x}"
### expect
$'a\nb'
### end
Loading