From 83893558f9ee9af398e0955c66b38e23042328c8 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 25 Jul 2022 16:32:04 +0200 Subject: [PATCH] Make ESCAPE_NO_PRINTABLES behavior a bit less weird MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the fix for #3892, this escaping style escapes \n to \\n as well as \\ to \\\\ \' to \\' I believe these two are the only printable characters that are escaped with ESCAPE_NO_PRINTABLES. The rationale is probably to keep the encoding unambiguous and reversible. However that doesn't justify escaping the single quote. Probably this was an accident, so let's revert that part. This has the nice effect that single quotes will no longer be escaped when rendered in the completion pager (which is consistent with other special characters). Try it: complete : -a "aaa\'\; aaaa\'\;" -f Also this makes the error output of builtin bind consistent: $ bind -e --preset \; $ bind -e --preset \' $ bind \; bind: No binding found for sequence “;” $ bind \' bind: No binding found for sequence “'” the last line is clearly better than the old version: bind: No binding found for sequence “\'” In general, the fact that ESCAPE_NO_PRINTABLES escapes the (printable) backslash is weird but I guess it's fine because it looks more consistent to users, even though the result is an undocumented subset of the fish language. --- src/common.cpp | 2 +- tests/checks/set.fish | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 8124c0424..d3252bcf0 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -941,7 +941,7 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring case L'\\': case L'\'': { need_escape = need_complex_escape = true; - out += L'\\'; + if (escape_printables || c == L'\\') out += L'\\'; out += *in; break; } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index 65d40f0cc..9b290da4d 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -553,7 +553,7 @@ set --show var1 #CHECK: $var1: set in local scope, unexported, with 0 elements #CHECK: $var1: set in global scope, unexported, with 2 elements #CHECK: $var1[1]: |goodbye| -#CHECK: $var1[2]: |and don\'t come back| +#CHECK: $var1[2]: |and don't come back| #CHECK: $var1: set in universal scope, unexported, with 1 elements #CHECK: $var1[1]: |hello|