diff options
| author | Mattias EngdegÄrd | 2019-02-24 22:12:52 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-03-02 15:35:28 +0100 |
| commit | da758046da74e33273265cd2e72a8aa1a0c9c7e3 (patch) | |
| tree | 4337523f0b56c12d69f27a91ee0a1b61376c0e7e /test | |
| parent | dbffbe08815644fd30404891ef81496277ed27da (diff) | |
| download | emacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.tar.gz emacs-da758046da74e33273265cd2e72a8aa1a0c9c7e3.zip | |
rx: fix `or' ordering by adding argument to regexp-opt
The rx `or' form may reorder its arguments in an unpredictable way,
contrary to user expectation, since it sometimes uses `regexp-opt'.
Add a NOREORDER option to `regexp-opt' for preventing it from
producing a reordered regexp (Bug#34641).
* doc/lispref/searching.texi (Regular Expression Functions):
* etc/NEWS (Lisp Changes in Emacs 27.1):
Describe the new regexp-opt NOREORDER argument.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Add NOREORDER.
Make no attempt at regexp improvement if the set of strings contains
a prefix of another string.
(regexp-opt--contains-prefix): New.
* lisp/emacs-lisp/rx.el (rx-or): Call regexp-opt with NOREORDER.
* test/lisp/emacs-lisp/rx-tests.el: Test rx `or' form match order.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/rx-tests.el | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index e14feda347f..fa3d9b0d5ea 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el | |||
| @@ -92,5 +92,18 @@ | |||
| 92 | (*? "e") (+? "f") (\?? "g") (?? "h")))) | 92 | (*? "e") (+? "f") (\?? "g") (?? "h")))) |
| 93 | "a*b+c?d?e*?f+?g??h??"))) | 93 | "a*b+c?d?e*?f+?g??h??"))) |
| 94 | 94 | ||
| 95 | (ert-deftest rx-or () | ||
| 96 | ;; Test or-pattern reordering (Bug#34641). | ||
| 97 | (let ((s "abc")) | ||
| 98 | (should (equal (and (string-match (rx (or "abc" "ab" "a")) s) | ||
| 99 | (match-string 0 s)) | ||
| 100 | "abc")) | ||
| 101 | (should (equal (and (string-match (rx (or "ab" "abc" "a")) s) | ||
| 102 | (match-string 0 s)) | ||
| 103 | "ab")) | ||
| 104 | (should (equal (and (string-match (rx (or "a" "ab" "abc")) s) | ||
| 105 | (match-string 0 s)) | ||
| 106 | "a")))) | ||
| 107 | |||
| 95 | (provide 'rx-tests) | 108 | (provide 'rx-tests) |
| 96 | ;; rx-tests.el ends here. | 109 | ;; rx-tests.el ends here. |