diff --git a/src/common.rs b/src/common.rs index dd0fedeb3..90d2b93dc 100644 --- a/src/common.rs +++ b/src/common.rs @@ -122,6 +122,8 @@ bitflags! { const SYMBOLIC = 1 << 3; /// Escape : and = const SEPARATORS = 1 << 4; + /// Escape , + const COMMA = 1 << 5; } } @@ -183,6 +185,7 @@ pub fn escape_string(s: &wstr, style: EscapeStringStyle) -> WString { fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString { let escape_printables = !flags.contains(EscapeFlags::NO_PRINTABLES); let escape_separators = flags.contains(EscapeFlags::SEPARATORS); + let escape_comma = flags.contains(EscapeFlags::COMMA); let no_quoted = flags.contains(EscapeFlags::NO_QUOTED); let no_tilde = flags.contains(EscapeFlags::NO_TILDE); let no_qmark = feature_test(FeatureFlag::qmark_noglob); @@ -300,6 +303,13 @@ fn escape_string_script(input: &wstr, flags: EscapeFlags) -> WString { } out.push(c); } + ',' => { + if escape_comma { + need_escape = true; + out.push('\\'); + } + out.push(c); + } '&' | '$' | ' ' | '#' | '<' | '>' | '(' | ')' | '[' | ']' | '{' | '}' | '?' | '*' | '|' | ';' | '"' | '%' | '~' => { diff --git a/src/expand.rs b/src/expand.rs index 26ab7da40..b5934c48f 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -8,9 +8,9 @@ use crate::builtins::shared::{ STATUS_INVALID_ARGS, STATUS_NOT_EXECUTABLE, STATUS_READ_TOO_MUCH, STATUS_UNMATCHED_WILDCARD, }; use crate::common::{ - char_offset, charptr2wcstring, escape, escape_string_for_double_quotes, unescape_string, - valid_var_name_char, wcs2zstring, UnescapeFlags, UnescapeStringStyle, EXPAND_RESERVED_BASE, - EXPAND_RESERVED_END, + char_offset, charptr2wcstring, escape, escape_string, escape_string_for_double_quotes, + unescape_string, valid_var_name_char, wcs2zstring, EscapeFlags, EscapeStringStyle, + UnescapeFlags, UnescapeStringStyle, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, }; use crate::complete::{CompleteFlags, Completion, CompletionList, CompletionReceiver}; use crate::env::{EnvVar, Environment}; @@ -1096,7 +1096,7 @@ pub fn expand_cmdsubst( } for sub_item in sub_res { - let sub_item2 = escape(&sub_item); + let sub_item2 = escape_string(&sub_item, EscapeStringStyle::Script(EscapeFlags::COMMA)); for tail_item in &*tail_expand { let mut whole_item = WString::new(); whole_item.reserve(paren_begin + 1 + sub_item2.len() + 1 + tail_item.completion.len()); diff --git a/tests/checks/braces.fish b/tests/checks/braces.fish index 061c3c45b..930007500 100644 --- a/tests/checks/braces.fish +++ b/tests/checks/braces.fish @@ -48,3 +48,6 @@ world} end #CHECK: '{hello #CHECK: world}' + +echo {a(echo ,)b} +#CHECK: {a,b}