From 6072ea1900a0559142b07c8fb21b15e070773046 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 3 Dec 2022 22:34:52 +0100 Subject: [PATCH] Fix false positive cd higlighting when token ends in slash We wrongly highlight this as prefix when actually the trailing slash should invalidate it. Turns out path normalization drops the slash, so let's sidestep that. Fixes #9394 --- src/fish_tests.cpp | 1 + src/highlight.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index faf376d2c..e1c13cdea 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2874,6 +2874,7 @@ static void test_is_potential_path() { do_test(is_potential_path(L"alpha/", true, wds, ctx, PATH_REQUIRE_DIR)); do_test(is_potential_path(L"aard", true, wds, ctx, 0)); do_test(!is_potential_path(L"aard", false, wds, ctx, 0)); + do_test(!is_potential_path(L"alp/", true, wds, ctx, PATH_REQUIRE_DIR | PATH_FOR_CD)); do_test(!is_potential_path(L"balpha/", true, wds, ctx, PATH_REQUIRE_DIR)); do_test(!is_potential_path(L"aard", true, wds, ctx, PATH_REQUIRE_DIR)); diff --git a/src/highlight.cpp b/src/highlight.cpp index 2800f5708..7645573b3 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -236,6 +236,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, bool at_cursor, for (const wcstring &wd : directories) { if (ctx.check_cancel()) return false; wcstring abs_path = path_apply_working_directory(clean_potential_path_fragment, wd); + bool must_be_full_dir = abs_path.at(abs_path.size() - 1) == L'/'; if (flags & PATH_FOR_CD) { abs_path = normalize_path(abs_path); } @@ -250,7 +251,6 @@ bool is_potential_path(const wcstring &potential_path_fragment, bool at_cursor, // 1. If the argument ends with a slash, it must be a valid directory, no prefix. // 2. If the cursor is not at the argument, it means the user is definitely not typing it, // so we can skip the prefix-match. - bool must_be_full_dir = abs_path.at(abs_path.size() - 1) == L'/'; if (must_be_full_dir || !at_cursor) { struct stat buf; if (0 == wstat(abs_path, &buf) && (!at_cursor || S_ISDIR(buf.st_mode))) {