[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint e882b71 42/44: Detect regexps spliced into [...]
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint e882b71 42/44: Detect regexps spliced into [...] |
Date: |
Tue, 26 Mar 2019 12:57:31 -0400 (EDT) |
branch: externals/relint
commit e882b71ed3ce20fb4088cb5fd7d7726555b330d8
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Detect regexps spliced into [...]
Look for attempts to splice the product of regexp-generating functions
such as regexp-quote into an [...] construct, using concat or format.
---
relint.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/relint.el b/relint.el
index 844373f..65af095 100644
--- a/relint.el
+++ b/relint.el
@@ -678,6 +678,67 @@
(format "`%s' cannot be used for arguments to `%s'"
(car reg-gen) skip-function)))))
+;; Look for a format expression that suggests insertion of a regexp
+;; into a character alternative: "[%s]" where the corresponding format
+;; parameter is regexp-generating.
+(defun relint--check-format-mixup (template args file pos path)
+ (let ((nargs (length args))
+ (index 0)
+ (start 0))
+ (while (and (< index nargs)
+ (string-match (rx
+ ;; An unescaped [, and some leading chars
+ (opt (or bos (not (any "\\")))
+ (0+ "\\\\")
+ (group "[")
+ (0+ (not (any "]"))))
+ ;; Any %-sequence
+ "%"
+ (opt (1+ digit) "$")
+ (0+ digit)
+ (opt "." (0+ digit))
+ (group (any "%sdioxXefgcS")))
+ template start))
+ (let ((bracket (match-beginning 1))
+ (type (string-to-char (match-string 2 template)))
+ (next (match-end 0)))
+ (when (and bracket (eq type ?s))
+ (let ((reg-gen (relint--regexp-generators (nth index args) nil)))
+ (when reg-gen
+ (relint--report
+ file pos (cons (+ index 2) path)
+ (format
+ "Value from `%s' cannot be spliced into `[...]'"
+ (car reg-gen))))))
+ (unless (eq type ?%)
+ (setq index (1+ index)))
+ (setq start next)))))
+
+;; Look for concat args that suggest insertion of a regexp into a
+;; character alternative: "[" followed by a regexp-generating
+;; expression.
+(defun relint--check-concat-mixup (args file pos path)
+ (let ((index 1))
+ (while (consp args)
+ (let ((arg (car args)))
+ (when (and (stringp arg)
+ (cdr args)
+ (string-match-p (rx (or bos (not (any "\\")))
+ (0+ "\\\\")
+ "["
+ (0+ (not (any "]")))
+ eos)
+ arg))
+ (let ((reg-gen (relint--regexp-generators (cadr args) nil)))
+ (when reg-gen
+ (relint--report
+ file pos (cons (1+ index) path)
+ (format
+ "Value from `%s' cannot be spliced into `[...]'"
+ (car reg-gen)))))))
+ (setq index (1+ index))
+ (setq args (cdr args)))))
+
(defun relint--check-form-recursively-1 (form file pos path)
(pcase form
(`(,(or `defun `defmacro `defsubst)
@@ -777,6 +838,12 @@
(relint--check-skip-set-provenance
(car form) skip-arg file pos (cons 1 path))
)
+ (`(concat . ,args)
+ (relint--check-concat-mixup args file pos path))
+ (`(format ,template-arg . ,args)
+ (let ((template (relint--get-string template-arg file pos path)))
+ (when template
+ (relint--check-format-mixup template args file pos path))))
(`(,(or `defvar `defconst `defcustom)
,name ,re-arg . ,rest)
(when (symbolp name)
- [elpa] branch externals/relint created (now ee70350), Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0604fad 43/44: Use a custom mode for the *relint* buffer, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint ee70350 44/44: FSF copyright, URL, and increment version to 1.5, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0fd1d46 29/44: Rename trawl to relint, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint e882b71 42/44: Detect regexps spliced into [...],
Mattias Engdegård <=
- [elpa] externals/relint c1b92cc 36/44: Wrap and evaluate defined functions passed as parameters, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d4a6d46 37/44: Evaluate some more functions, macros and special forms, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 019f4cf 10/44: Rewrite the partial evaluator and extend coverage, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 365dc91 41/44: Check bad skip-set provenance, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint a1829d7 39/44: Refactor the file scanning and linting code, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0f76132 40/44: Add README.org, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint e824db0 38/44: Expand locally defined macros, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint c215d54 34/44: More careful evaluation of if, when, unless, and, or, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 15c799e 35/44: Evaluate calls to functions defined in the same file., Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 2d1f488 32/44: mapcar on non-list sequence, Mattias Engdegård, 2019/03/26