Subject: Re: bug#78097: 30.1; editorconfig can pass nil to file-name-directory

From: Eli Zaretskii <[email-masked]>
Date: Sat, 03 May 2025 11:56:31 +0300

> From: "Peter J. Jones" <[email-masked]>
> Date: Sun, 27 Apr 2025 14:58:50 +0200
> 
> When a function called from `editorconfig-get-local-variables-functions'
> returns an alist, but there is no .editorconfig file in the directory
> tree, the `editorconfig--get-dir-local-variables' function will pass nil
> to `file-name-directory', causing an error (stringp nil).
> 
> This happens because `editorconfig--get-dir-local-variables' calls
> `editorconfig-core-get-nearest-editorconfig', which returns nil, and
> passes that nil on to `file-name-directory'.
> 
> The following patch fixes the problem:
> 
> --- editorconfig.el.orig        2025-04-27 14:52:35.208707072 +0200
> +++ editorconfig.el     2025-04-27 14:53:19.423741999 +0200
> @@ -739,11 +739,10 @@
>        ;; settings from each file individually and let hack-dir-local merge
>        ;; them because hack-dir-local doesn't have the notion of "unset",
>        ;; and because the conversion of `indent_size' depends on `tab_width'.
> -      (when alist
> -        (cons
> -         (file-name-directory (editorconfig-core-get-nearest-editorconfig
> -                               buffer-file-name))
> -         alist)))))
> +      (when-let* ((alist)
> +                  (file (editorconfig-core-get-nearest-editorconfig
> +                         buffer-file-name)))
> +        (cons (file-name-directory file) alist)))))
>  
>  ;;;###autoload
>  (define-minor-mode editorconfig-mode

Thanks.

Stefan, any comments?  If the patch is okay, on what branch should it
be installed?