GNU bug report logs - #78097
30.1; editorconfig can pass nil to file-name-directory

Previous Next

Package: emacs;

Reported by: "Peter J. Jones" <mlists <at> devalot.com>

Date: Sun, 27 Apr 2025 15:31:02 UTC

Severity: normal

Found in version 30.1

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 78097 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Peter J. Jones" <mlists <at> devalot.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 78097 <at> debbugs.gnu.org
Subject: Re: bug#78097: 30.1; editorconfig can pass nil to file-name-directory
Date: Sat, 03 May 2025 11:56:31 +0300
> From: "Peter J. Jones" <mlists <at> devalot.com>
> 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?




This bug report was last modified 54 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.