From: Stefan Monnier Date: Mon, 8 Jul 2024 21:09:31 +0000 (-0400) Subject: editorconfig-core-handle.el: Fix regressions in fnmatch handling X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2046964510bd5c41f98d812cc0721c5f82fbafa6;p=emacs.git editorconfig-core-handle.el: Fix regressions in fnmatch handling * lisp/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. (cherry picked from commit dce31372a60a9d37591671b8570169c9117e416a) --- diff --git a/lisp/editorconfig-core-handle.el b/lisp/editorconfig-core-handle.el index 96d0723d9e0..73c26288287 100644 --- a/lisp/editorconfig-core-handle.el +++ b/lisp/editorconfig-core-handle.el @@ -127,9 +127,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))) @@ -143,7 +143,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))))) (defun editorconfig-core-handle--parse-file (conf) "Parse EditorConfig file CONF.