From ab0fdd19183054df84544c7b13bff32092f2fcdc Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 6 Jun 2024 17:07:43 +0200 Subject: [PATCH] Remove unescape_string_in_place Only used in two places and did not do anything sensible --- src/builtins/complete.rs | 11 +++++------ src/common.rs | 7 ------- src/highlight.rs | 7 +++---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/builtins/complete.rs b/src/builtins/complete.rs index c0feb9c04..4014ec208 100644 --- a/src/builtins/complete.rs +++ b/src/builtins/complete.rs @@ -1,7 +1,5 @@ use super::prelude::*; -use crate::common::{ - unescape_string, unescape_string_in_place, ScopeGuard, UnescapeFlags, UnescapeStringStyle, -}; +use crate::common::{unescape_string, ScopeGuard, UnescapeFlags, UnescapeStringStyle}; use crate::complete::{complete_add_wrapper, complete_remove_wrapper, CompletionRequestOptions}; use crate::highlight::colorize; use crate::highlight::highlight_shell; @@ -536,10 +534,11 @@ pub fn complete(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> // The input data is meant to be something like you would have on the command // line, e.g. includes backslashes. The output should be raw, i.e. unescaped. So // we need to unescape the command line. See #1127. - unescape_string_in_place( - &mut faux_cmdline_with_completion, + faux_cmdline_with_completion = unescape_string( + &faux_cmdline_with_completion, UnescapeStringStyle::Script(UnescapeFlags::default()), - ); + ) + .expect("Unescaping commandline to complete failed"); } // Append any description. diff --git a/src/common.rs b/src/common.rs index 7e800013e..effea3508 100644 --- a/src/common.rs +++ b/src/common.rs @@ -494,13 +494,6 @@ pub fn unescape_string(input: &wstr, style: UnescapeStringStyle) -> Option bool { - unescape_string(s, style) - .map(|unescaped| *s = unescaped) - .is_some() -} - /// Returns the unescaped version of input, or None on error. fn unescape_string_internal(input: &wstr, flags: UnescapeFlags) -> Option { let mut result = WString::new(); diff --git a/src/highlight.rs b/src/highlight.rs index fac1a7510..f5031a709 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -7,7 +7,7 @@ use crate::builtins::shared::builtin_exists; use crate::color::RgbColor; use crate::common::{ - unescape_string_in_place, valid_var_name, valid_var_name_char, UnescapeFlags, ASCII_MAX, + unescape_string, valid_var_name, valid_var_name_char, UnescapeFlags, ASCII_MAX, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END, }; use crate::env::Environment; @@ -677,9 +677,8 @@ fn range_is_potential_path( // Get the node source, unescape it, and then pass it to is_potential_path along with the // working directory (as a one element list). let mut result = false; - let mut token = (src[range.start()..range.end()]).to_owned(); - if unescape_string_in_place( - &mut token, + if let Some(mut token) = unescape_string( + &src[range.start()..range.end()], crate::common::UnescapeStringStyle::Script(UnescapeFlags::SPECIAL), ) { // Big hack: is_potential_path expects a tilde, but unescape_string gives us HOME_DIRECTORY.