aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-09-25 22:18:36 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-09-25 22:18:36 -0700
commitb511550917d9b657237392268ba07cd38e6b3fcc (patch)
tree12a1011f5f2be317765612a07ef7be14aa75e789
parent7935b86cb2f06385f5fcb8774efcc0ae8f47a0b8 (diff)
Revert "Prepend ./ to "flag-like file" wildcard expansions and completions"
This reverts commit 316d7004a3d4f6905f36301b6d5c9ebd934f11fa. Reverts fix for 1519 in light of #1713 Conflicts: fish_tests.cpp
-rw-r--r--expand.h5
-rw-r--r--fish_tests.cpp31
-rw-r--r--wildcard.cpp59
-rw-r--r--wildcard.h4
4 files changed, 25 insertions, 74 deletions
diff --git a/expand.h b/expand.h
index fe13a145..14a4f477 100644
--- a/expand.h
+++ b/expand.h
@@ -60,10 +60,7 @@ enum
EXPAND_SKIP_HOME_DIRECTORIES = 1 << 9,
/** Allow fuzzy matching */
- EXPAND_FUZZY_MATCH = 1 << 10,
-
- /** Requests that flag-like files not be sanitized. Sanitization means that a completion '--foo' that represents a file will be replaced by './--foo'. */
- EXPAND_NO_SANITIZE_FLAGLIKE_FILES = 1 << 11
+ EXPAND_FUZZY_MATCH = 1 << 10
};
typedef int expand_flags_t;
diff --git a/fish_tests.cpp b/fish_tests.cpp
index ffff6ff4..7c2de13a 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -1414,44 +1414,23 @@ static void test_expand()
if (system("mkdir -p /tmp/fish_expand_test/")) err(L"mkdir failed");
if (system("touch /tmp/fish_expand_test/.foo")) err(L"touch failed");
if (system("touch /tmp/fish_expand_test/bar")) err(L"touch failed");
- if (system("touch /tmp/fish_expand_test/-flag1")) err(L"touch failed");
- if (system("touch /tmp/fish_expand_test/--flag2")) err(L"touch failed");
// This is checking that .* does NOT match . and .. (https://github.com/fish-shell/fish-shell/issues/270). But it does have to match literal components (e.g. "./*" has to match the same as "*"
expand_test(L"/tmp/fish_expand_test/.*", 0, L"/tmp/fish_expand_test/.foo", 0,
L"Expansion not correctly handling dotfiles");
expand_test(L"/tmp/fish_expand_test/./.*", 0, L"/tmp/fish_expand_test/./.foo", 0,
L"Expansion not correctly handling literal path components in dotfiles");
- expand_test(L"/tmp/fish_expand_test/*flag?", 0, L"/tmp/fish_expand_test/--flag2", L"/tmp/fish_expand_test/-flag1", 0,
- L"Expansion not correctly handling flag-like files");
- // Verify that flag-like file expansions never expand to flags
- char saved_wd[PATH_MAX + 1] = {};
- if (getcwd(saved_wd, sizeof saved_wd) != NULL && !chdir("/tmp/fish_expand_test/"))
+ if (! expand_test(L"/tmp/fish_expand_test/.*", 0, L"/tmp/fish_expand_test/.foo", 0))
{
- expand_test(L"*flag?", 0, L"./--flag2", L"./-flag1", 0,
- L"Expansion not correctly handling flag-like files in cwd");
- expand_test(L"*flag?", EXPAND_NO_SANITIZE_FLAGLIKE_FILES, L"--flag2", L"-flag1", 0,
- L"Expansion (no sanitize) not correctly handling flag-like files in cwd");
-
- // For suffix-only completions, we don't attempt any sanitization
- expand_test(L"*flag", ACCEPT_INCOMPLETE, L"2", L"1", 0,
- L"Expansion (accept incomplete) not correctly handling flag-like files in cwd");
-
- if (!chdir(saved_wd))
- {
- if (system("rm -Rf /tmp/fish_expand_test")) err(L"rm failed");
- }
- else
- {
- err(L"chdir restoration failed");
- }
+ err(L"Expansion not correctly handling dotfiles");
}
- else
+ if (! expand_test(L"/tmp/fish_expand_test/./.*", 0, L"/tmp/fish_expand_test/./.foo", 0))
{
- err(L"chdir failed");
+ err(L"Expansion not correctly handling literal path components in dotfiles");
}
+ if (system("rm -Rf /tmp/fish_expand_test")) err(L"rm failed");
}
static void test_fuzzy_match(void)
diff --git a/wildcard.cpp b/wildcard.cpp
index b2a61092..eb29c4e6 100644
--- a/wildcard.cpp
+++ b/wildcard.cpp
@@ -306,15 +306,7 @@ static bool wildcard_complete_internal(const wcstring &orig,
}
/* Note: out_completion may be empty if the completion really is empty, e.g. tab-completing 'foo' when a file 'foo' exists. */
- if ((expand_flags & EXPAND_NO_SANITIZE_FLAGLIKE_FILES) == 0 && string_prefixes_string(L"-", out_completion))
- {
- append_completion(out, L"./" + out_completion, out_desc, flags, fuzzy_match);
- }
- else
- {
- append_completion(out, out_completion, out_desc, flags, fuzzy_match);
- }
-
+ append_completion(out, out_completion, out_desc, flags, fuzzy_match);
return true;
}
@@ -636,7 +628,7 @@ static void wildcard_completion_allocate(std::vector<completion_t> &list,
wcstring sb;
wcstring munged_completion;
- complete_flags_t complete_flags = 0;
+ int flags = 0;
int stat_res, lstat_res;
int stat_errno=0;
@@ -690,7 +682,7 @@ static void wildcard_completion_allocate(std::vector<completion_t> &list,
if (sz >= 0 && S_ISDIR(buf.st_mode))
{
- complete_flags |= COMPLETE_NO_SPACE;
+ flags |= COMPLETE_NO_SPACE;
munged_completion = completion;
munged_completion.push_back(L'/');
if (wants_desc)
@@ -709,14 +701,8 @@ static void wildcard_completion_allocate(std::vector<completion_t> &list,
}
}
- /* Hackish. If the fullname is longer than the completion, it means we have a prefix. An example is completing "./foo" where the fullname is "./foo" and the completion might be "foo". In that case, we will pass "foo" to wildcard_complete, and it may choose to sanitize the file by appending a ./ to the front (since it doesn't know it already has one). Avoid that by cleaing the sanitize flag. */
- if (completion.size() < fullname.size())
- {
- expand_flags |= EXPAND_NO_SANITIZE_FLAGLIKE_FILES;
- }
-
const wcstring &completion_to_use = munged_completion.empty() ? completion : munged_completion;
- wildcard_complete(completion_to_use, wc, sb.c_str(), NULL, list, expand_flags, complete_flags);
+ wildcard_complete(completion_to_use, wc, sb.c_str(), NULL, list, expand_flags, flags);
}
/**
@@ -724,9 +710,8 @@ static void wildcard_completion_allocate(std::vector<completion_t> &list,
expansion flags specified. flags can be a combination of
EXECUTABLES_ONLY and DIRECTORIES_ONLY.
*/
-static bool test_flags(const wcstring &filename_str, expand_flags_t flags)
+static bool test_flags(const wchar_t *filename, expand_flags_t flags)
{
- const wchar_t * const filename = filename_str.c_str();
if (flags & DIRECTORIES_ONLY)
{
struct stat buf;
@@ -761,22 +746,11 @@ static bool test_flags(const wcstring &filename_str, expand_flags_t flags)
return true;
}
-/** Appends a completion to the completion list, if the string is missing from the set. Sanitizing means that if the file looks like a flag (has a leading -), we prepend a ./ */
-static void insert_and_sanitize_completion_if_missing(const wcstring &str, std::vector<completion_t> &out, expand_flags_t flags, std::set<wcstring> &completion_set)
+/** Appends a completion to the completion list, if the string is missing from the set. */
+static void insert_completion_if_missing(const wcstring &str, std::vector<completion_t> &out, std::set<wcstring> &completion_set)
{
if (completion_set.insert(str).second)
- {
- if ((flags & EXPAND_NO_SANITIZE_FLAGLIKE_FILES) == 0 && string_prefixes_string(L"-", str))
- {
- // sanitized
- append_completion(out, L"./" + str);
- }
- else
- {
- // not sanitized
- append_completion(out, str);
- }
- }
+ append_completion(out, str);
}
/**
@@ -882,11 +856,11 @@ static int wildcard_expand_internal(const wchar_t *wc,
wcstring next;
while (wreaddir(dir, next))
{
- if (! next.empty() && next.at(0) != L'.')
+ if (next[0] != L'.')
{
wcstring long_name = make_path(base_dir, next);
- if (test_flags(long_name, flags))
+ if (test_flags(long_name.c_str(), flags))
{
wildcard_completion_allocate(out, long_name, next, L"", flags);
}
@@ -896,7 +870,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
else
{
res = 1;
- insert_and_sanitize_completion_if_missing(base_dir, out, flags, completion_set);
+ insert_completion_if_missing(base_dir, out, completion_set);
}
}
else
@@ -914,7 +888,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
std::vector<completion_t> test;
if (wildcard_complete(name_str, wc, L"", NULL, test, flags & EXPAND_FUZZY_MATCH, 0))
{
- if (test_flags(long_name, flags))
+ if (test_flags(long_name.c_str(), flags))
{
wildcard_completion_allocate(out, long_name, name_str, wc, flags);
@@ -932,7 +906,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
{
/*
In recursive mode, we are only
- interested in adding files. Directories
+ interested in adding files -directories
will be added in the next pass.
*/
struct stat buf;
@@ -943,7 +917,7 @@ static int wildcard_expand_internal(const wchar_t *wc,
}
if (! skip)
{
- insert_and_sanitize_completion_if_missing(long_name, out, flags, completion_set);
+ insert_completion_if_missing(long_name, out, completion_set);
}
res = 1;
}
@@ -1085,7 +1059,10 @@ static int wildcard_expand_internal(const wchar_t *wc,
}
-static int wildcard_expand(const wchar_t *wc, const wchar_t *base_dir, expand_flags_t flags, std::vector<completion_t> &out)
+int wildcard_expand(const wchar_t *wc,
+ const wchar_t *base_dir,
+ expand_flags_t flags,
+ std::vector<completion_t> &out)
{
size_t c = out.size();
diff --git a/wildcard.h b/wildcard.h
index b09aa64f..8c542221 100644
--- a/wildcard.h
+++ b/wildcard.h
@@ -84,9 +84,7 @@ bool wildcard_has(const wcstring &, bool internal);
bool wildcard_has(const wchar_t *, bool internal);
/**
- Matches the string against the wildcard, and if the wildcard is a
- possible completion of the string, the remainder of the string is
- inserted into the out vector.
+ Test wildcard completion
*/
bool wildcard_complete(const wcstring &str,
const wchar_t *wc,