aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2021-02-18 11:11:11 +0100
committerMattias EngdegÄrd2021-02-18 11:32:50 +0100
commit892db042a0d85caeea9a4969073e13f525eb9f60 (patch)
tree9f788aa6079518167673d2510b8ae5306fe5c872
parent8358637936c455d906675932db4cbf90c35b6c53 (diff)
downloademacs-892db042a0d85caeea9a4969073e13f525eb9f60.tar.gz
emacs-892db042a0d85caeea9a4969073e13f525eb9f60.zip
Fix rx `regexp` form with deprecated syntax
The argument of the rx `regexp` form is assumed to evaluate to a valid regexp, but certain kinds of deprecated but still accepted usage were not handled correctly, such as unescaped literal (special) characters: (rx "a" (regexp "*")) => "a*" which is wrong. Handle these cases; there is no extra trouble. * lisp/emacs-lisp/rx.el (rx--translate-regexp): Force bracketing of single special characters. * test/lisp/emacs-lisp/rx-tests.el (rx-regexp): Add test case.
-rw-r--r--lisp/emacs-lisp/rx.el2
-rw-r--r--test/lisp/emacs-lisp/rx-tests.el2
2 files changed, 3 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index b29b870061d..58584f300c9 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -890,7 +890,7 @@ Return (REGEXP . PRECEDENCE)."
890 (* (or (seq "[:" (+ (any "a-z")) ":]") 890 (* (or (seq "[:" (+ (any "a-z")) ":]")
891 (not (any "]")))) 891 (not (any "]"))))
892 "]") 892 "]")
893 anything 893 (not (any "*+?^$[\\"))
894 (seq "\\" 894 (seq "\\"
895 (or anything 895 (or anything
896 (seq (any "sScC_") anything) 896 (seq (any "sScC_") anything)
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 63d7c7b91ea..388c5e86b4c 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -391,6 +391,8 @@
391 (let ((x "a*")) 391 (let ((x "a*"))
392 (should (equal (rx (regexp x) "b") 392 (should (equal (rx (regexp x) "b")
393 "\\(?:a*\\)b")) 393 "\\(?:a*\\)b"))
394 (should (equal (rx "a" (regexp "*"))
395 "a\\(?:*\\)"))
394 (should (equal (rx "" (regexp x) (eval "")) 396 (should (equal (rx "" (regexp x) (eval ""))
395 "a*")))) 397 "a*"))))
396 398