Skip to content

Commit

Permalink
Fix rx regexp form with deprecated syntax
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattiase committed Feb 18, 2021
1 parent 8358637 commit 892db04
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lisp/emacs-lisp/rx.el
Expand Up @@ -890,7 +890,7 @@ Return (REGEXP . PRECEDENCE)."
(* (or (seq "[:" (+ (any "a-z")) ":]")
(not (any "]"))))
"]")
anything
(not (any "*+?^$[\\"))
(seq "\\"
(or anything
(seq (any "sScC_") anything)
Expand Down
2 changes: 2 additions & 0 deletions test/lisp/emacs-lisp/rx-tests.el
Expand Up @@ -391,6 +391,8 @@
(let ((x "a*"))
(should (equal (rx (regexp x) "b")
"\\(?:a*\\)b"))
(should (equal (rx "a" (regexp "*"))
"a\\(?:*\\)"))
(should (equal (rx "" (regexp x) (eval ""))
"a*"))))

Expand Down

0 comments on commit 892db04

Please sign in to comment.