Move uses of trim_quotes to unescape for filenames (#5398)

* Move uses of trim_quotes to unescape for filenames

* Fix Windows tests
This commit is contained in:
JT
2022-05-02 06:37:20 +12:00
committed by GitHub
parent 80d57d70cd
commit 98ab31e15e
4 changed files with 43 additions and 41 deletions

View File

@ -1,7 +1,7 @@
use crate::completions::{
file_completions::file_path_completion, Completer, CompletionOptions, MatchAlgorithm, SortBy,
};
use nu_parser::{trim_quotes, FlatShape};
use nu_parser::{unescape_unquote_string, FlatShape};
use nu_protocol::{
engine::{EngineState, StateWorkingSet},
Span,
@ -237,9 +237,10 @@ impl Completer for CommandCompletion {
.map(move |x| {
if self.flat_idx == 0 {
// We're in the command position
if x.1.starts_with('"') && !matches!(preceding_byte.get(0), Some(b'^')) {
let trimmed = trim_quotes(x.1.as_bytes());
let trimmed = String::from_utf8_lossy(trimmed).to_string();
if (x.1.starts_with('"') || x.1.starts_with('\'') || x.1.starts_with('`'))
&& !matches!(preceding_byte.get(0), Some(b'^'))
{
let (trimmed, _) = unescape_unquote_string(x.1.as_bytes(), span);
let expanded = nu_path::canonicalize_with(trimmed, &cwd);
if let Ok(expanded) = expanded {