From a6b598518c4bf6dfc587cfb2b61fa5fb04b99494 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Tue, 3 Dec 2019 15:17:37 +0100 Subject: [PATCH] Avoid duplicated character classes in rx For example, (any digit digit) should produce "[[:digit:]]", not "[[:digit:][:digit:]]". * lisp/emacs-lisp/rx.el (rx--translate-any): Deduplicate character classes. * test/lisp/emacs-lisp/rx-tests.el (rx-any): Add test case. --- lisp/emacs-lisp/rx.el | 4 +++- test/lisp/emacs-lisp/rx-tests.el | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 52a35ffa2a7..6fde27831a0 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -376,7 +376,9 @@ If NEGATED, negate the sense." (push (cons arg arg) conses)) ((and (symbolp arg) (let ((class (cdr (assq arg rx--char-classes)))) - (and class (push class classes))))) + (and class + (or (memq class classes) + (push class classes)))))) (t (error "Invalid rx `any' argument: %s" arg)))) (let ((items ;; Translate strings and conses into nonoverlapping intervals, diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 4ecc805aead..26e39f8c8ed 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el @@ -128,7 +128,9 @@ (should (equal (rx (any) (not (any))) "\\`a\\`[^z-a]")) (should (equal (rx (any "") (not (any ""))) - "\\`a\\`[^z-a]"))) + "\\`a\\`[^z-a]")) + (should (equal (rx (any space ?a digit space)) + "[a[:space:][:digit:]]"))) (ert-deftest rx-pcase () (should (equal (pcase "a 1 2 3 1 1 b" -- 2.39.2