summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2023-12-09 19:46:07 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2023-12-09 19:49:33 -0500
commit6cc1418fc3e8107cab2c9824c367ba7762235aef (patch)
tree5e62b6d439dd27bea3f90719f796acd92743be50 /lisp/files.el
parent1da0fccc646d1921782dd6d701bc86004cfb3732 (diff)
downloademacs-6cc1418fc3e8107cab2c9824c367ba7762235aef.tar.gz
(file-expand-wildcards): Handle patterns ending in "/"
The bug was encountered via the ls-lisp advice on Dired but it actually affects all uses of `file-expand-wildcards`, so better fix it there. * lisp/files.el (file-expand-wildcards): Fix bug#60819. * lisp/ls-lisp.el (ls-lisp--dired): Undo commit b365a7cc32e2. * test/lisp/files-tests.el (files-tests--expand-wildcards): New test.
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el51
1 files changed, 29 insertions, 22 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 047854d3939..3c1d0c30e67 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7547,27 +7547,34 @@ default directory. However, if FULL is non-nil, they are absolute."
(dolist (dir (nreverse dirs))
(when (or (null dir) ; Possible if DIRPART is not wild.
(file-accessible-directory-p dir))
- (let ((this-dir-contents
- ;; Filter out "." and ".."
- (delq nil
- (mapcar (lambda (name)
- (unless (string-match "\\`\\.\\.?\\'"
- (file-name-nondirectory name))
- name))
- (directory-files
- (or dir ".") full
- (if regexp
- ;; We're matching each file name
- ;; element separately.
- (concat "\\`" nondir "\\'")
- (wildcard-to-regexp nondir)))))))
- (setq contents
- (nconc
- (if (and dir (not full))
- (mapcar (lambda (name) (concat dir name))
- this-dir-contents)
- this-dir-contents)
- contents)))))
+ (if (equal "" nondir)
+ ;; `nondir' is "" when the pattern ends in "/". Basically ""
+ ;; refers to the directory itself, like ".", but it's not
+ ;; among the names returned by `directory-files', so we have
+ ;; to special-case it.
+ (push (or dir nondir) contents)
+ (let ((this-dir-contents
+ ;; Filter out "." and ".."
+ (delq nil
+ (mapcar (lambda (name)
+ (unless (string-match "\\`\\.\\.?\\'"
+ (file-name-nondirectory
+ name))
+ name))
+ (directory-files
+ (or dir ".") full
+ (if regexp
+ ;; We're matching each file name
+ ;; element separately.
+ (concat "\\`" nondir "\\'")
+ (wildcard-to-regexp nondir)))))))
+ (setq contents
+ (nconc
+ (if (and dir (not full))
+ (mapcar (lambda (name) (concat dir name))
+ this-dir-contents)
+ this-dir-contents)
+ contents))))))
contents)))
(defcustom find-sibling-rules nil
@@ -7757,7 +7764,7 @@ need to be passed verbatim to shell commands."
(purecopy "ls"))
"Absolute or relative name of the `ls'-like program.
This is used by `insert-directory' and `dired-insert-directory'
-(thus, also by `dired'). For Dired, this should ideally point to
+\(thus, also by `dired'). For Dired, this should ideally point to
GNU ls, or another version of ls that supports the \"--dired\"
flag. See `dired-use-ls-dired'.