aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_tests.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-09-24 22:01:33 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-09-24 22:06:43 -0700
commit316d7004a3d4f6905f36301b6d5c9ebd934f11fa (patch)
treef631fe6cd81f6d07ca755f812c73c6b3923e4d02 /fish_tests.cpp
parent1096b1acd508aa9752d4fb6b8286b2b61cd8df1a (diff)
Prepend ./ to "flag-like file" wildcard expansions and completions
If a wildcard or completion expands to a file that begins with one or more dashes, prepend a ./ to it so that it doesn't get parsed as an option. Fixes #1519
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r--fish_tests.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp
index 8d30d5f4..85327cca 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -1387,6 +1387,8 @@ 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 "*"
if (! expand_test(L"/tmp/fish_expand_test/.*", 0, L"/tmp/fish_expand_test/.foo", 0))
@@ -1397,6 +1399,32 @@ static void test_expand()
{
err(L"Expansion not correctly handling literal path components in dotfiles");
}
+ if (! expand_test(L"/tmp/fish_expand_test/*flag?", 0, L"/tmp/fish_expand_test/--flag2", L"/tmp/fish_expand_test/-flag1", 0))
+ {
+ err(L"Expansion not correctly handling flag-like files");
+ }
+
+ // Verify that flag-like file expansions never expand to flags
+ char saved_wd[PATH_MAX + 1] = {};
+ getcwd(saved_wd, sizeof saved_wd);
+ if (chdir("/tmp/fish_expand_test/")) err(L"chdir failed");
+ if (! expand_test(L"*flag?", 0, L"./--flag2", L"./-flag1", 0))
+ {
+ err(L"Expansion not correctly handling flag-like files in cwd");
+ }
+ if (! expand_test(L"*flag?", EXPAND_NO_SANITIZE_FLAGLIKE_FILES, L"--flag2", L"-flag1", 0))
+ {
+ err(L"Expansion not correctly handling flag-like files in cwd");
+ }
+
+
+ // For suffix-only completions, we don't attempt any sanitization
+ if (! expand_test(L"*flag", ACCEPT_INCOMPLETE, L"2", L"1", 0))
+ {
+ err(L"Expansion not correctly handling flag-like files in cwd");
+ }
+
+ if (chdir(saved_wd)) err(L"chdir restoration failed");
if (system("rm -Rf /tmp/fish_expand_test")) err(L"rm failed");
}