diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index f328389af..b1eefe5d1 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -1,5 +1,5 @@ use super::prelude::*; -use crate::common::{Named, bytes2wcstring, escape, get_by_sorted_name}; +use crate::common::{Named, bytes2wcstring, escape, get_by_sorted_name, str2wcstring}; use crate::fds::BorrowedFdFile; use crate::io::OutputStream; use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG; @@ -716,7 +716,7 @@ pub fn builtin_wperror(program_name: &wstr, streams: &mut IoStreams) { streams.err.append(program_name); streams.err.append(L!(": ")); if err.0 != 0 { - let werr = WString::from_str(&err.to_string()); + let werr = str2wcstring(err.to_string()); streams.err.append(&werr); streams.err.append_char('\n'); } diff --git a/src/builtins/string/match.rs b/src/builtins/string/match.rs index 6c3067195..af1ca900f 100644 --- a/src/builtins/string/match.rs +++ b/src/builtins/string/match.rs @@ -3,6 +3,7 @@ use std::num::NonZeroUsize; use super::*; +use crate::common::str2wcstring; use crate::env::{EnvVar, EnvVarFlags}; use crate::flog::flog; use crate::parse_util::unescape_wildcards; @@ -307,7 +308,7 @@ fn validate_capture_group_names( capture_group_names: &[Option], ) -> Result<(), RegexError> { for name in capture_group_names.iter().filter_map(|n| n.as_ref()) { - let wname = WString::from_str(name); + let wname = str2wcstring(name); if EnvVar::flags_for(&wname).contains(EnvVarFlags::READ_ONLY) { return Err(RegexError::InvalidCaptureGroupName(wname)); } diff --git a/src/builtins/test.rs b/src/builtins/test.rs index e06608539..f971b8cc4 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -1088,6 +1088,7 @@ pub fn test(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Bui mod tests { use super::test as builtin_test; use crate::builtins::prelude::*; + use crate::common::str2wcstring; use crate::io::{IoChain, OutputStream}; use crate::tests::prelude::*; @@ -1100,7 +1101,7 @@ fn run_one_test_test_mbracket(expected: i32, lst: &[&str], bracket: bool) -> boo argv.push(L!("test").to_owned()); } for s in lst { - argv.push(WString::from_str(s)); + argv.push(str2wcstring(s)); } if bracket { argv.push(L!("]").to_owned()) diff --git a/src/complete.rs b/src/complete.rs index 3d443dea3..5d8c9250e 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -2633,6 +2633,7 @@ mod tests { sort_and_prioritize, }; use crate::abbrs::{self, Abbreviation, with_abbrs_mut}; + use crate::common::str2wcstring; use crate::env::{EnvMode, EnvSetMode, Environment}; use crate::io::IoChain; use crate::operation_context::{ @@ -3281,7 +3282,7 @@ macro_rules! perform_one_completion_cd_test { vars.parent .vars - .insert(L!("AUTOSUGGEST_TEST_LOC").to_owned(), WString::from_str(wd)); + .insert(L!("AUTOSUGGEST_TEST_LOC").to_owned(), str2wcstring(wd)); perform_one_autosuggestion_cd_test!("cd $AUTOSUGGEST_TEST_LOC/0", "foobar/", &vars); perform_one_autosuggestion_cd_test!("cd ~/test_autosuggest_suggest_specia", "l/", &vars); diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 3f4eb1ea5..dba823ae5 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -248,6 +248,7 @@ fn populate_variables(s: &[u8], out_vars: &mut VarTable) -> UvarFormat { let Ok(line) = std::str::from_utf8(line) else { continue; }; + // TODO: investigate whether this should use str2wcstring wide_line = WString::from_str(line); match format { diff --git a/src/event.rs b/src/event.rs index 9f98597a6..e75fdc852 100644 --- a/src/event.rs +++ b/src/event.rs @@ -7,7 +7,7 @@ use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::{Arc, Mutex}; -use crate::common::{ScopeGuard, escape}; +use crate::common::{ScopeGuard, escape, str2wcstring}; use crate::flog::flog; use crate::io::{IoChain, IoStreams}; use crate::job_group::MaybeJobId; @@ -402,7 +402,7 @@ pub fn get_desc(parser: &Parser, evt: &Event) -> WString { EventDescription::Any => unreachable!(), }; - WString::from_str(&s) + str2wcstring(&s) } /// Add an event handler. diff --git a/src/expand.rs b/src/expand.rs index 4dbca809e..f60739779 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -1591,6 +1591,7 @@ mod tests { use crate::abbrs::Abbreviation; use crate::abbrs::{self}; use crate::abbrs::{with_abbrs, with_abbrs_mut}; + use crate::common::str2wcstring; use crate::complete::{CompletionList, CompletionReceiver}; use crate::env::{EnvMode, EnvStackSetResult}; use crate::expand::{ExpandResultCode, expand_to_receiver}; @@ -1953,7 +1954,7 @@ fn test_expand_overflow() { // Make a list of 64 elements, then expand it cartesian-style 64 times. // This is far too large to expand. let vals: Vec = (1..=64).map(|i| i.to_wstring()).collect(); - let expansion = WString::from_str(&str::repeat("$bigvar", 64)); + let expansion = str2wcstring(str::repeat("$bigvar", 64)); let parser = TestParser::new(); parser.vars().push(true); diff --git a/src/highlight/file_tester.rs b/src/highlight/file_tester.rs index 2cb103caa..cce1b87d2 100644 --- a/src/highlight/file_tester.rs +++ b/src/highlight/file_tester.rs @@ -426,6 +426,7 @@ pub fn fs_is_case_insensitive( #[cfg(test)] mod tests { use super::{FileTester, IsErr, IsFile, PathFlags, is_potential_path}; + use crate::common::osstr2wcstring; use crate::env::EnvStack; use crate::operation_context::{EXPANSION_LIMIT_DEFAULT, OperationContext}; use crate::prelude::*; @@ -454,10 +455,7 @@ fn filepath(&self, name: &str) -> PathBuf { } fn file_tester(&self) -> FileTester<'_> { - FileTester::new( - WString::from_str(self.tempdir.path().to_str().unwrap()), - &self.ctx, - ) + FileTester::new(osstr2wcstring(self.tempdir.path()), &self.ctx) } } diff --git a/src/localization/gettext.rs b/src/localization/gettext.rs index 4c3e24388..bccc295e1 100644 --- a/src/localization/gettext.rs +++ b/src/localization/gettext.rs @@ -41,8 +41,9 @@ fn gettext(message: MaybeStatic) -> &'static wstr { LazyLock::new(|| Mutex::new(HashMap::default())); let mut localizations_to_wide = LOCALIZATION_TO_WIDE.lock().unwrap(); if !localizations_to_wide.contains_key(localized_str) { - let localization_wstr = - Box::leak(WString::from_str(localized_str).into_boxed_utfstr()); + use crate::common::str2wcstring; + + let localization_wstr = Box::leak(str2wcstring(localized_str).into_boxed_utfstr()); localizations_to_wide.insert(localized_str, localization_wstr); } return localizations_to_wide.get(localized_str).unwrap(); diff --git a/src/localization/settings.rs b/src/localization/settings.rs index 35bb116ae..ec7aad4c8 100644 --- a/src/localization/settings.rs +++ b/src/localization/settings.rs @@ -88,6 +88,10 @@ fn append_space_separated_list>( for lang in list { string.push(' '); string.push_utfstr(&crate::common::escape( + // lang is already PUA-encoded at this point. The reason we convert the PUA-encoded + // WString into a String is to enable comparison with the language names we have + // available. We could use WString for lang, but that would require converting our + // stored languages names as WString as well. WString::from_str(lang.as_ref()).as_utfstr(), )); } diff --git a/src/parser.rs b/src/parser.rs index 71680e7ca..c2a30adca 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1487,6 +1487,7 @@ mod tests { use crate::ast::{ self, Ast, Castable, JobList, JobPipeline, Kind, Node, Traversal, is_same_node, }; + use crate::common::str2wcstring; use crate::env::EnvStack; use crate::expand::ExpandFlags; use crate::io::{IoBufferfill, IoChain}; @@ -1513,7 +1514,7 @@ macro_rules! detect_errors { } fn detect_argument_errors(src: &str) -> Result<(), ParserTestErrorBits> { - let src = WString::from_str(src); + let src = str2wcstring(src); let ast = ast::parse_argument_list(&src, ParseTreeFlags::default(), None); if ast.errored() { return Err(ParserTestErrorBits::ERROR);