Unexpand abbreviations' variable names before completing them

Fixes #6166
This commit is contained in:
Johannes Altmanninger 2019-10-06 13:28:42 +02:00 committed by Fabian Homborg
parent 1602902e12
commit 7017a2fcf9
3 changed files with 8 additions and 1 deletions

View File

@ -1211,7 +1211,9 @@ std::map<wcstring, wcstring> get_abbreviations(const environment_t &vars) {
std::map<wcstring, wcstring> result;
for (const wcstring &name : names) {
if (string_prefixes_string(prefix, name)) {
result[name.substr(prefix.size())] = vars.get(name)->as_string();
wcstring key;
unescape_string(name.substr(prefix.size()), &key, UNESCAPE_DEFAULT, STRING_STYLE_VAR);
result[key] = vars.get(name)->as_string();
}
}
return result;

View File

@ -177,6 +177,7 @@ wcstring replace_home_directory_with_tilde(const wcstring &str, const environmen
maybe_t<wcstring> expand_abbreviation(const wcstring &src, const environment_t &vars);
/// \return a snapshot of all abbreviations as a map abbreviation->expansion.
/// The abbreviations are unescaped, i.e. they may not be valid variable identifiers (#6166).
std::map<wcstring, wcstring> get_abbreviations(const environment_t &vars);
// Terrible hacks

View File

@ -85,3 +85,7 @@ abbr __abbr11 omega11
abbr __abbr12 omega12
abbr -r __abbr11 __abbr12
# CHECKERR: abbr --rename: Abbreviation __abbr12 already exists, cannot rename __abbr11
abbr __abbr-with-dashes omega
complete -C__abbr-with
# CHECK: __abbr-with-dashes Abbreviation: omega