[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1d97984 227/348: Ensure that ivy--regex-ignore-order alway
From: |
Oleh Krehel |
Subject: |
[elpa] master 1d97984 227/348: Ensure that ivy--regex-ignore-order always returns legal regexps |
Date: |
Sat, 8 Apr 2017 11:04:01 -0400 (EDT) |
branch: master
commit 1d9798403f98ad4472ad42861acec614b2ae7859
Author: Wilfred Hughes <address@hidden>
Commit: Wilfred Hughes <address@hidden>
Ensure that ivy--regex-ignore-order always returns legal regexps
The input from the user may not be a valid regexp. Even when a user
types a valid regexp, there may be points where the intermediate value
is not a valid regexp.
Fall back to a literal string match if the input is not a valid regexp.
Fixes #765.
---
ivy-test.el | 4 +++-
ivy.el | 15 +++++++++++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index cb2befa..ef8aa51 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -169,7 +169,9 @@
(should (equal (ivy--regex-ignore-order "one two !three four")
'(("one" . t) ("two" . t) ("three") ("four"))))
(should (equal (ivy--regex-ignore-order "!three four")
- '(("" . t) (("three") ("four"))))))
+ '(("" . t) (("three") ("four")))))
+ (should (equal (ivy--regex-ignore-order "foo[ bar[xy]")
+ '(("foo\\[" . t) ("bar[xy]" . t)))))
(ert-deftest ivy--format ()
(should (string= (let ((ivy--index 10)
diff --git a/ivy.el b/ivy.el
index d1b9487..03a6c92 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1959,16 +1959,27 @@ When GREEDY is non-nil, join words in a greedy way."
".*?")))))
ivy--regex-hash)))))
+(defun ivy--legal-regex-p (str)
+ "Return t if STR is valid regular expression."
+ (condition-case nil
+ (progn
+ (string-match-p str "")
+ t)
+ (invalid-regexp nil)))
+
(defun ivy--regex-ignore-order--part (str &optional discard)
"Re-build regex from STR by splitting at spaces.
-Ignore the order of each group."
+Ignore the order of each group. If any substring is not a valid
+regex, treat it as a literal string."
(let* ((subs (split-string str " +" t))
(len (length subs)))
(cl-case len
(0
"")
(t
- (mapcar (lambda (x) (cons x (not discard)))
+ (mapcar (lambda (s)
+ (cons (if (ivy--legal-regex-p s) s (regexp-quote s))
+ (not discard)))
subs)))))
(defun ivy--regex-ignore-order (str)
- [elpa] master 1c09e99 156/348: ivy.el (ivy-call): Use select-window, not with-ivy-window, (continued)
- [elpa] master 1c09e99 156/348: ivy.el (ivy-call): Use select-window, not with-ivy-window, Oleh Krehel, 2017/04/08
- [elpa] master ec42e8a 177/348: swiper.el (swiper-multi-action-1): Fix regression, Oleh Krehel, 2017/04/08
- [elpa] master 778c325 183/348: ivy.el (ivy-call): Don't switch windows for 'identity action, Oleh Krehel, 2017/04/08
- [elpa] master 1e96d20 201/348: ivy-overlay.el (ivy-display-function-overlay): Fix up, Oleh Krehel, 2017/04/08
- [elpa] master f5276b0 180/348: Add char-fold-to-regexp option to swiper, Oleh Krehel, 2017/04/08
- [elpa] master 9f5f6e0 202/348: ivy-overlay.el (ivy-overlay-cleanup): Fixup, Oleh Krehel, 2017/04/08
- [elpa] master 74d83ab 216/348: Sort virtual buffers after open buffers., Oleh Krehel, 2017/04/08
- [elpa] master 17f8fb3 219/348: ivy.el (ivy-switch-buffer-other-window): Obey ivy-ignore-buffers, Oleh Krehel, 2017/04/08
- [elpa] master 07388d0 226/348: Shrink ivy to suitable height when reading actions., Oleh Krehel, 2017/04/08
- [elpa] master 2237916 223/348: ivy.el (ivy-call): setq default-directory instead of let, Oleh Krehel, 2017/04/08
- [elpa] master 1d97984 227/348: Ensure that ivy--regex-ignore-order always returns legal regexps,
Oleh Krehel <=
- [elpa] master 7e02815 235/348: Fix counsel-rg to follow matching candidate, Oleh Krehel, 2017/04/08
- [elpa] master 530b7de 246/348: ivy.el: Use predicate when reading file names, Oleh Krehel, 2017/04/08
- [elpa] master 1c801a0 243/348: Ignore TAGS buffers in swiper-all, Oleh Krehel, 2017/04/08
- [elpa] master 6519ecc 248/348: ivy.el (ivy-call): Don't mess with default-directory, Oleh Krehel, 2017/04/08
- [elpa] master 721db4c 244/348: counsel.el (counsel-grep-post-action-hook): New hook for counsel-ag/grep/pt, Oleh Krehel, 2017/04/08
- [elpa] master 49acd4c 242/348: Remap scroll-up/down-command instead of assigning C-v/M-v so page up/down works, Oleh Krehel, 2017/04/08
- [elpa] master c322613 240/348: ivy.el (ivy--magic-file-slash): Fix pasting "/etc/", Oleh Krehel, 2017/04/08
- [elpa] master 1304925 239/348: ivy.el (ivy--directory-done): Fix broken "/ssh:", Oleh Krehel, 2017/04/08
- [elpa] master 359a6c8 241/348: Address multiple problems with counsel-rg, Oleh Krehel, 2017/04/08
- [elpa] master 2ed3da4 252/348: counsel.el: Fix byte-compile warning, Oleh Krehel, 2017/04/08