highlight: normalize path when validating path for cd

As builtin cd does.

Fixes #6915.
This commit is contained in:
Johannes Altmanninger 2020-04-19 07:01:25 +02:00
parent 9f45ff63d3
commit 0fb58ab625
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -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,