From 0fb58ab62550ec2887b2feeecd869a8875ffcdd6 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 19 Apr 2020 07:01:25 +0200 Subject: [PATCH] highlight: normalize path when validating path for cd As builtin cd does. Fixes #6915. --- src/highlight.cpp | 7 +++++-- src/highlight.h | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/highlight.cpp b/src/highlight.cpp index f94898077..59f4692e3 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -253,7 +253,10 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l for (const wcstring &wd : directories) { if (ctx.check_cancel()) return false; - const wcstring abs_path = path_apply_working_directory(clean_potential_path_fragment, wd); + wcstring abs_path = path_apply_working_directory(clean_potential_path_fragment, wd); + if (flags & PATH_FOR_CD) { + abs_path = normalize_path(abs_path); + } // Skip this if it's empty or we've already checked it. if (abs_path.empty() || checked_paths.count(abs_path)) continue; @@ -330,7 +333,7 @@ static bool is_potential_cd_path(const wcstring &path, const wcstring &working_d } // Call is_potential_path with all of these directories. - return is_potential_path(path, directories, ctx, flags | PATH_REQUIRE_DIR); + return is_potential_path(path, directories, ctx, flags | PATH_REQUIRE_DIR | PATH_FOR_CD); } // Given a plain statement node in a parse tree, get the command and return it, expanded diff --git a/src/highlight.h b/src/highlight.h index 5e409f8f8..556098084 100644 --- a/src/highlight.h +++ b/src/highlight.h @@ -122,7 +122,9 @@ enum { // The path must be to a directory. PATH_REQUIRE_DIR = 1 << 0, // Expand any leading tilde in the path. - PATH_EXPAND_TILDE = 1 << 1 + PATH_EXPAND_TILDE = 1 << 1, + // Normalize directories before resolving, as "cd". + PATH_FOR_CD = 1 << 2, }; typedef unsigned int path_flags_t; bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_list_t &directories,