bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in rl_filename_completion_function (with patch!)


From: Stefan H. Holek
Subject: Bug in rl_filename_completion_function (with patch!)
Date: Tue, 25 Oct 2022 09:51:20 +0200

Hi All,

There is an issue that has been bothering me for quite some time now, and that
I finally got to the bottom of. It concerns the dirname passed to opendir in
rl_filename_completion_function (complete.c).

If the dirname requires tilde expansion it is expanded, and if it requires
dequoting it is dequoted. However, if a dirname requires BOTH tilde expansion
AND dequoting (e.g.: ~stefan/funny\ dir/) only the former is performed and
filename completion fails as a result.

Turns out the if/else construct preparing the dirname is missing a branch
where both expansion and dequoting are performed. The patch below adds this
branch and makes ~stefan/funny\ dir/ work as expected.


diff --git a/complete.c b/complete.c
index e5d224e..138c8d3 100644
--- a/complete.c
+++ b/complete.c
@@ -2551,6 +2551,14 @@ rl_filename_completion_function (const char *text, int 
state)
          xfree (dirname);
          dirname = savestring (users_dirname);
        }
+      else if (tilde_dirname == 1 && rl_completion_found_quote && 
rl_filename_dequoting_function)
+       {
+         /* So far we have dequoted users_dirname and tilde expanded dirname.
+            In this branch we must do both. */
+         temp = tilde_expand (users_dirname);
+         xfree (dirname);
+         dirname = temp;
+       }
       directory = opendir (dirname);
 
       /* Now dequote a non-null filename.  FILENAME will not be NULL, but may


The choice was to either dequote dirname or to tilde expand users_dirname. We
decided on the second option, because it avoids having to call the
user-defined rl_filename_dequoting_function twice for the same path.

If tilde expansion is attempted but fails, it will be attempted a second time
when the "both" branch is hit. To prevent this, we propose to leave
tilde_dirname at 0 if the expansion does not succeed.


diff --git a/complete.c b/complete.c
index e5d224e..7f0d765 100644
--- a/complete.c
+++ b/complete.c
@@ -2526,7 +2526,9 @@ rl_filename_completion_function (const char *text, int 
state)
          temp = tilde_expand (dirname);
          xfree (dirname);
          dirname = temp;
-         tilde_dirname = 1;
+         /* Set flag if the expansion was successful. */
+         if (*dirname != '~')
+           tilde_dirname = 1;
        }
 
       /* We have saved the possibly-dequoted version of the directory name


Please let me know if you prefer different formats or forums. The
instructions said "send mail to bug-readline" and here we are. :-)

Thank you,
Stefan

-- 
Stefan H. Holek
stefan@epy.co.at




reply via email to

[Prev in Thread] Current Thread [Next in Thread]