summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-07-30 15:30:38 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2023-07-30 18:12:19 +0200
commit2b8796eea1979fe6891ab9d80cd126fe8980167a (patch)
tree0e49ad64bf11942baf797aecf87723ecc8842f00 /lisp/emacs-lisp
parentba60070b81c4b507b856269031a17b99e9f5e77c (diff)
downloademacs-2b8796eea1979fe6891ab9d80cd126fe8980167a.tar.gz
emacs-2b8796eea1979fe6891ab9d80cd126fe8980167a.tar.bz2
emacs-2b8796eea1979fe6891ab9d80cd126fe8980167a.zip
Fix rx wrong-code bug: ranges starting with ^
(rx (in (?^ . ?a))) was incorrectly translated to "[^-a]". Change it so that we get "[_-a^]" instead. * lisp/emacs-lisp/rx.el (rx--generate-alt): Split ranges starting with `^` occurring first in a non-negated character alternative. * test/lisp/emacs-lisp/rx-tests.el (rx-any): Add and adapt tests. (cherry picked from commit 5f5d668ac7917d61e9366fe0c3efd7b542671c3d)
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/rx.el20
1 files changed, 13 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index 46f61c26bc4..30195cbae32 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -445,13 +445,19 @@ classes."
(setcar dash-l ?.)) ; Reduce --x to .-x
(setq items (nconc items '((?- . ?-))))))
- ;; Deal with leading ^ and range ^-x.
- (when (and (consp (car items))
- (eq (caar items) ?^)
- (cdr items))
- ;; Move ^ and ^-x to second place.
- (setq items (cons (cadr items)
- (cons (car items) (cddr items)))))
+ ;; Deal with leading ^ and range ^-x in non-negated set.
+ (when (and (eq (car-safe (car items)) ?^)
+ (not negated))
+ (if (eq (cdar items) ?^)
+ ;; single leading ^
+ (when (cdr items)
+ ;; Move the ^ to second place.
+ (setq items (cons (cadr items)
+ (cons (car items) (cddr items)))))
+ ;; Split ^-x to _-x^
+ (setq items (cons (cons ?_ (cdar items))
+ (cons '(?^ . ?^)
+ (cdr items))))))
(cond
;; Empty set: if negated, any char, otherwise match-nothing.