mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
editorconfig-core-handle.el: Fix silent misparse
See https://github.com/editorconfig/editorconfig-emacs/issues/380 * lisp/editorconfig-core-handle.el (editorconfig-core-handle--parse-file): Fix regexp to not inadvertently match LF. Remove an O(N²) complexity. Use `line-number-at-pos`. * lisp/editorconfig.el (editorconfig--get-coding-system): Don't let errors propagate.
This commit is contained in:
parent
188ad4f909
commit
e233513d28
2 changed files with 19 additions and 20 deletions
|
|
@ -166,10 +166,7 @@ If CONF is not found return nil."
|
|||
;; nil when pattern not appeared yet, "" when pattern is empty ("[]")
|
||||
(pattern nil)
|
||||
;; Alist of properties for current PATTERN
|
||||
(props ())
|
||||
|
||||
;; Current line num
|
||||
(current-line-number 1))
|
||||
(props ()))
|
||||
(while (not (eobp))
|
||||
(skip-chars-forward " \t\f")
|
||||
(cond
|
||||
|
|
@ -187,7 +184,7 @@ If CONF is not found return nil."
|
|||
(setq props nil)
|
||||
(setq pattern newpattern)))
|
||||
|
||||
((looking-at "\\([^=: \t][^=:]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
|
||||
((looking-at "\\([^=: \n\t][^=:\n]*\\)[ \t]*[=:][ \t]*\\(.*?\\)[ \t]*$")
|
||||
(let ((key (downcase (string-trim (match-string 1))))
|
||||
(value (match-string 2)))
|
||||
(if pattern
|
||||
|
|
@ -197,12 +194,10 @@ If CONF is not found return nil."
|
|||
top-props))))
|
||||
|
||||
(t (error "Error while reading config file: %s:%d:\n %s\n"
|
||||
conf current-line-number
|
||||
conf (line-number-at-pos)
|
||||
(buffer-substring-no-properties (line-beginning-position)
|
||||
(line-end-position)))))
|
||||
(setq current-line-number (1+ current-line-number))
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- current-line-number)))
|
||||
(forward-line 1))
|
||||
(when pattern
|
||||
(push (make-editorconfig-core-handle-section
|
||||
:name pattern
|
||||
|
|
|
|||
|
|
@ -658,6 +658,10 @@ F is that function, and FILENAME and ARGS are arguments passed to F."
|
|||
"Return the coding system to use according to EditorConfig.
|
||||
Meant to be used on `auto-coding-functions'."
|
||||
(defvar auto-coding-file-name) ;; Emacs≥30
|
||||
;; Not only we don't want that an error in the `.editorconfig' file
|
||||
;; prevents opening a file but we don't want an error to be dropped on
|
||||
;; the floor by some `ignore-errors' higher up.
|
||||
(with-demoted-errors "EditorConfig: %S"
|
||||
(when (and (stringp auto-coding-file-name)
|
||||
(file-name-absolute-p auto-coding-file-name)
|
||||
;; Don't recurse infinitely.
|
||||
|
|
@ -668,7 +672,7 @@ Meant to be used on `auto-coding-functions'."
|
|||
(props (editorconfig-call-get-properties-function
|
||||
auto-coding-file-name)))
|
||||
(editorconfig-merge-coding-systems (gethash 'end_of_line props)
|
||||
(gethash 'charset props)))))
|
||||
(gethash 'charset props))))))
|
||||
|
||||
(defun editorconfig--get-dir-local-variables ()
|
||||
"Return the directory local variables specified via EditorConfig.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue