diff --git a/src/expand.rs b/src/expand.rs index 4dee054d4..a3dd60607 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -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); diff --git a/src/wcstringutil.rs b/src/wcstringutil.rs index 79c751b20..3f8bff515 100644 --- a/src/wcstringutil.rs +++ b/src/wcstringutil.rs @@ -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] diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 178659fee..7beedfa2a 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -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 diff --git a/tests/checks/expansion.fish b/tests/checks/expansion.fish index 87c3f8758..ac6746674 100644 --- a/tests/checks/expansion.fish +++ b/tests/checks/expansion.fish @@ -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