Isolate hack for skipping internal separator

stage_wildcards has no need for INTERNAL_SEPARATOR. Remove it already
at this stage, to avoid the need to have the workaround in the generic
decoding routine.

Unfortunately we still can't add assert!(!fish_reserved_codepoint(c));
to wcs2bytes_callback, since builtin printf still passes arbitrary
characters. We should fix that later.

Test that printf now behaves correctly for INTERNAL_SEPARATOR.
Also add a regression test for 0c9b73e317.
This commit is contained in:
Johannes Altmanninger
2025-12-17 16:43:16 +01:00
parent ee2d99ecf3
commit 50bcc3cf4f
4 changed files with 20 additions and 11 deletions

View File

@@ -1394,6 +1394,8 @@ fn stage_home_and_self(
mut input: WString,
out: &mut CompletionReceiver,
) -> ExpandResult {
remove_internal_separator(&mut input, self.flags.contains(ExpandFlags::SKIP_WILDCARDS));
expand_home_directory(&mut input, self.ctx.vars());
if !feature_test(FeatureFlag::RemovePercentSelf) {
expand_percent_self(&mut input);
@@ -1406,15 +1408,11 @@ fn stage_home_and_self(
fn stage_wildcards(
&mut self,
mut path_to_expand: WString,
path_to_expand: WString,
out: &mut CompletionReceiver,
) -> ExpandResult {
let mut result = ExpandResult::ok();
remove_internal_separator(
&mut path_to_expand,
self.flags.contains(ExpandFlags::SKIP_WILDCARDS),
);
let has_wildcard = wildcard_has_internal(&path_to_expand); // e.g. ANY_STRING
let for_completions = self.flags.contains(ExpandFlags::FOR_COMPLETIONS);
let skip_wildcards = self.flags.contains(ExpandFlags::SKIP_WILDCARDS);

View File

@@ -1,7 +1,6 @@
//! Helper functions for working with wcstring.
use crate::common::{get_ellipsis_char, get_ellipsis_str};
use crate::expand::INTERNAL_SEPARATOR;
use crate::fallback::{fish_wcwidth, wcscasecmp, wcscasecmp_fuzzy};
use crate::wchar::{decode_byte_from_char, prelude::*};
@@ -322,11 +321,6 @@ pub fn wcs2bytes_callback(input: &wstr, mut func: impl FnMut(&[u8]) -> bool) ->
let mut converted = [0_u8; 4];
for c in input.chars() {
if c == INTERNAL_SEPARATOR {
// do nothing, this is important for ~$user handling
continue;
}
let bytes = if let Some(byte) = decode_byte_from_char(c) {
converted[0] = byte;
&converted[..=0]

View File

@@ -630,6 +630,9 @@ $fish -c 'echo \ufdd2"fart"'
echo (printf '\ufdd2foo') | string escape
# CHECK: \Xef\Xb7\X92foo
echo (printf '\ufdd8foo') | string escape
# CHECK: \Xef\Xb7\X98foo
printf '%s\n' "#!/bin/sh" 'echo $0' > $tmpdir/argv0.sh
chmod +x $tmpdir/argv0.sh
cd $tmpdir

View File

@@ -350,3 +350,17 @@ echo {asdf,~}
# CHECK: asdf /{{.*}}
echo {~}
# CHECK: {~}
function compare
test $argv[1] = $argv[2]
or begin
echo unexpected expansion result:
echo expected: $argv[1]
echo actual: $argv[2]
end
end
if string match -rq -- '^[\w.-]+$' $USER
set -l user_home "$(eval "echo ~$USER")"
compare $user_home "$(echo ~$USER)"
compare $user_home "$(echo ~(printf %s $USER))"
end