branch: scratch/editorconfig-cc
commit 1b1b1aceb1651123a8de47f721ea6f43e076d5c3
Author: 10sr <8.slas...@gmail.com>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Disallow setting mode when it is not listed in whitelist
---
 editorconfig.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/editorconfig.el b/editorconfig.el
index 5f6761b365..885d09e8f2 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -371,6 +371,10 @@ to non-nil when FINAL-NEWLINE is true."
              (> (string-to-number length) 0))
     (setq fill-column (string-to-number length))))
 
+(defvar editorconfig-file-type-emacs-whitelist
+  '()
+  "List of known `major-mode' that can be used for file_type_emacs value.")
+
 (defun editorconfig-set-major-mode-from-name (filetype)
   "Set buffer `major-mode' by FILETYPE.
 
@@ -382,7 +386,12 @@ FILETYPE should be s string like `\"ini\"`, if not nil or 
empty string."
                                    "-mode")))))
     (when mode
       (if (fboundp mode)
-          (editorconfig-apply-major-mode-safely mode)
+          (if (apply 'provided-mode-derived-p mode
+                     editorconfig-file-type-emacs-whitelist)
+              (editorconfig-apply-major-mode-safely mode)
+            (display-warning :error (format "Major-mode `%S' is not listed in 
`%S'"
+                                            mode
+                                            
'editorconfig-file-type-emacs-whitelist)))
         (display-warning :error (format "Major-mode `%S' not found"
                                         mode))
         nil))))

Reply via email to