Skip to content

Commit

Permalink
fixed escape char handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mitnk committed Jul 17, 2022
1 parent 60e717c commit 75b2cfb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 53 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# cicada Release Notes

## 0.9.31 - 2022.07.17

- fixed an escape char `\` handling issue.
- e.g. `alias c='printf "\ec"'` got `\` char removed.

## 0.9.30 - 2022-06-12

- added builtin: `vox create`
Expand Down
111 changes: 62 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition = "2021"
build = "src/build.rs"
name = "cicada"
version = "0.9.30"
version = "0.9.31"
authors = ["Hugo Wang <w@mitnk.com>"]

description = "A simple Bash-like Unix shell."
Expand Down
14 changes: 11 additions & 3 deletions src/parsers/parser_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn cmd_to_tokens(line: &str) -> Tokens {
// using semi_ok makes quite dirty here
// it is mainly for path completion like:
// $ ls "foo b<TAB>
// # then got `"foo bar"/`, then let tab again:
// # then got `"foo bar"/`, then hit tab again:
// $ ls "foo bar"/<TAB>
// # should got:
// $ ls "foo bar/the-single-file.txt"
Expand Down Expand Up @@ -247,8 +247,12 @@ pub fn cmd_to_tokens(line: &str) -> Tokens {
met_parenthesis = false;
}

if c == '\\' && sep != "'" {
has_backslash = true;
if c == '\\' {
if sep == "'" || !sep_second.is_empty() {
token.push(c)
} else {
has_backslash = true;
}
continue;
}

Expand Down Expand Up @@ -804,6 +808,10 @@ mod tests {
"1+2-3*(4/5.0)",
vec![("", "1+2-3*(4/5.0)"),],
),
(
"alias c='printf \"\\ec\"'",
vec![("", "alias"), ("", "c='printf \"\\ec\"'")],
),
];
for (left, right) in v {
println!("\ninput: {:?}", left);
Expand Down

0 comments on commit 75b2cfb

Please sign in to comment.