1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

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.
This commit is contained in:
Stefan Monnier 2024-07-08 17:09:31 -04:00
parent ed2986494c
commit dce31372a6

View File

@ -127,9 +127,9 @@ If HANDLE is nil return nil."
If HANDLE is nil return nil." If HANDLE is nil return nil."
(when handle (when handle
(let ((hash (make-hash-table)) (let* ((hash (make-hash-table))
(file (file-relative-name file (editorconfig-core-handle-path (dir (file-name-directory (editorconfig-core-handle-path handle)))
handle)))) (file (file-relative-name file dir)))
(dolist (section (editorconfig-core-handle-sections handle)) (dolist (section (editorconfig-core-handle-sections handle))
(cl-loop for (key . value) in (editorconfig-core-handle-section-get-properties section file) (cl-loop for (key . value) in (editorconfig-core-handle-section-get-properties section file)
do (puthash (intern key) value hash))) 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) (if (string-match-p "/" pattern)
(let ((pattern (replace-regexp-in-string "\\`/" "" pattern))) (let ((pattern (replace-regexp-in-string "\\`/" "" pattern)))
(editorconfig-fnmatch-p name 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) (defun editorconfig-core-handle--parse-file (conf)
"Parse EditorConfig file CONF. "Parse EditorConfig file CONF.