From: Mattias EngdegÄrd Date: Tue, 3 Dec 2019 14:17:37 +0000 (+0100) Subject: Avoid duplicated character classes in rx X-Git-Tag: emacs-27.0.90~456 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a6b598518c4bf6dfc587cfb2b61fa5fb04b99494;p=emacs.git 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. --- 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"