]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix rx `regexp` form with deprecated syntax
authorMattias Engdegård <mattiase@acm.org>
Thu, 18 Feb 2021 10:11:11 +0000 (11:11 +0100)
committerMattias Engdegård <mattiase@acm.org>
Thu, 18 Feb 2021 10:32:50 +0000 (11:32 +0100)
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.

lisp/emacs-lisp/rx.el
test/lisp/emacs-lisp/rx-tests.el

index b29b870061d2bb2a083342f325578f8d3f83987c..58584f300c9cdb26d279b33c58489d6ad95c056d 100644 (file)
@@ -890,7 +890,7 @@ Return (REGEXP . PRECEDENCE)."
                                (* (or (seq "[:" (+ (any "a-z")) ":]")
                                       (not (any "]"))))
                                "]")
-                          anything
+                          (not (any "*+?^$[\\"))
                           (seq "\\"
                                (or anything
                                    (seq (any "sScC_") anything)
index 63d7c7b91eae81778aefb0c67375a24ee95d95bc..388c5e86b4cfe9acecb7f3b89284d6bcd4535120 100644 (file)
   (let ((x "a*"))
     (should (equal (rx (regexp x) "b")
                    "\\(?:a*\\)b"))
+    (should (equal (rx "a" (regexp "*"))
+                   "a\\(?:*\\)"))
     (should (equal (rx "" (regexp x) (eval ""))
                    "a*"))))