[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] scratch/editorconfig d0a491fbf9: editorconfig-core-handle.el: F
From: |
Stefan Monnier |
Subject: |
[nongnu] scratch/editorconfig d0a491fbf9: editorconfig-core-handle.el: Fix regressions in fnmatch handling |
Date: |
Mon, 8 Jul 2024 16:40:00 -0400 (EDT) |
branch: scratch/editorconfig
commit d0a491fbf9607ec4fbf972b06a0d9893cd26bc6d
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
editorconfig-core-handle.el: Fix regressions in fnmatch handling
* editorconfig-core-handle.el
(editorconfig-core-handle-get-properties-hash): Fix computation of
relative file name.
(editorconfig-core-handle--fnmatch-p): Handle the case when `pattern`
doesn't have a `/` but does match the `/` character.
---
editorconfig-core-handle.el | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el
index 210593855f..20f52a3b97 100644
--- a/editorconfig-core-handle.el
+++ b/editorconfig-core-handle.el
@@ -131,9 +131,9 @@ If HANDLE is nil return nil."
If HANDLE is nil return nil."
(when handle
- (let ((hash (make-hash-table))
- (file (file-relative-name file (editorconfig-core-handle-path
- handle))))
+ (let* ((hash (make-hash-table))
+ (dir (file-name-directory (editorconfig-core-handle-path handle)))
+ (file (file-relative-name file dir)))
(dolist (section (editorconfig-core-handle-sections handle))
(cl-loop for (key . value) in
(editorconfig-core-handle-section-get-properties section file)
do (puthash (intern key) value hash)))
@@ -147,7 +147,11 @@ This function is a fnmatch with a few modification for
EditorConfig usage."
(if (string-match-p "/" pattern)
(let ((pattern (replace-regexp-in-string "\\`/" "" pattern)))
(editorconfig-fnmatch-p name pattern))
- (editorconfig-fnmatch-p (file-name-nondirectory name) pattern)))
+ ;; The match is not "anchored" so it can be either in the current dir or
+ ;; in a subdir. Contrary to Zsh patterns, editorconfig's `**/foo' does
+ ;; not match `foo', so we need to split the problem into two matches.
+ (or (editorconfig-fnmatch-p name pattern)
+ (editorconfig-fnmatch-p name (concat "**/" pattern)))))
(defsubst editorconfig-core-handle--string-trim (str)
"Remove leading and trailing whitespaces from STR."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] scratch/editorconfig d0a491fbf9: editorconfig-core-handle.el: Fix regressions in fnmatch handling,
Stefan Monnier <=